Reputation: 1399
To track the anchor link clicks as pageviews in universal analytics i used the following code on my single page website.
var hashtag = /#\S+/
jQuery('.navbar li a').click(function(){
var match = jQuery(this).attr('href').match(hashtag);
ga('send', 'pageview', '/' + match[0]);
})
/*
Now i changed to googel tag manager. Universal analytics is still working but the anchor links are not tracked.
Does anyone have an idea what the problem might be or how i can track the anchor link pageviews with google tag manager?
Upvotes: 1
Views: 3842
Reputation: 484
You can use a macro (variable) to form URL (get link text) for virtual pageview and Universal Analytics tag with this macro in More setting - Basic configuration - Document path.
In new GTM you should use More settings - Fields to Set - Field Name= page, Value={{your variable}}.
The firing rule for this tag will be click on link on your page.
Upvotes: 2