Google Analytics and visited CSS links

I have 4 sites linked to each other and tracked by the GA method:

onclick="_gaq.push(...)" 

This will result in a GA parameter with a random value in the URL, for example:

 http://example.com/great-page/?_ga=1.78527441.491437166.1409121868 

But I want every visited link to be in CSS style:

 a:visited {color: purple} 

But this will not be correctly framed thanks to the random GA parameter in the URL, which is always different.

Any ideas on the style of visited links with GA parameters in the URL?

+5
source share
1 answer

I assume that you have already created a canonical URL for each page. If not, the canonical URL is the URL that the current page appears to have.

On each page, add the following Javascript code:

 history.pushState({id:1},document.title,CANONICAL) 

This changes the URL displayed to the user without reloading the page.

For example, if you use PHP, it will be something like:

 history.pushState({id:1},document.title,"<?php echo get_canonical() ?>") 

This will add the canonical URL to the browser history. Then, for each link, set the href attribute to a canonical URL.

This has added the benefits of changing ugly URLs like http://example.com/page?utm_source=blah - http://example.com/page (after processing Google Analytics utm_source )

0
source

Source: https://habr.com/ru/post/1208369/


All Articles