Save full page url and referrer url to Adobe Analytics using javascript

One of my most popular blog post is how to save full page and/or referrer url to eVar variable using processing rules in Adobe Analytics. You can read the post in here. I absolutely love to know the full url. There have been millions of cases where I have solved many analytics problems and mysteries using the full url info. By “full url” we can see the url with all the possible parameters.

If you are not familiar with processing rules or you don’t have access to use those, you can always use javascript to save the same information to Adobe Analytics too (or to any other Analytics tools). I’m sure you can use tag management to populate the javascript or add the javascript directly to Adobe’s script like I do and populate the code before sending the hit to Adobe’s server.

There are actually two reasons why I prefer javascript coding vs. processing rules. Processing rules are absolutely great for different purposes, but impossible to do any (complex) own modifications how to collect/edit the data. Using javascript you can do pretty much anything to manipulate the data before sending it. I’ll give an example soon. Of course processing rules can be only choice if you don’t have access to the script or not using tag management (or have to wait eternity to get production updates).

Shut up and show me the money code:

s.eVar1 = window.location.href;
s.eVar2 = document.referrer;

Oh, the simplicity. That’s it.

Why this is better than using processing rules? One word, debugging. Yes, if you have coded something to the site you can debug it and get the confirmation that data is collected correctly. If using processing rules, you have to wait to see data in stats and see is everything ok or not.

There was one case when I noticed that there was some sensitive information included on the full url and that way it was collected to Adobe Analytics as well. Yes, this is a never good idea to show sensitive information in the url, but sometimes there could be special cases etc. We found some javascript and regular expression methods to censor data if certain parameters are included in the url and that way you won’t collect any personal identification or sensitive data to your analytics tool. My initial reaction was to make javascript hack and not to collect any data when url contains certain words, luckily I have more advanced javascript users around me, and of course we should collect every url, but let’s just censor the values that are inside these sensitive parameters. Below is just example with some parameters that could be sensitive information:

s.eVar1 = window.location.href;
s.eVar1 = s.eVar1.replace(/(\?|&)(phonenumber=)[^&]*(&|$)/i,"$1$2$3");
s.eVar1 = s.eVar1.replace(/(\?|&)(UserStreetAddress=)[^&]*(&|$)/i,"$1$2$3");
s.eVar1 = s.eVar1.replace(/(\?|&)(password=)[^&]*(&|$)/i,"$1$2$3");
s.eVar2 = document.referrer;
s.eVar2 = s.eVar2.replace(/(\?|&)(phonenumber=)[^&]*(&|$)/i,"$1$2$3");
s.eVar2 = s.eVar2.replace(/(\?|&)(UserStreetAddress=)[^&]*(&|$)/i,"$1$2$3");
s.eVar2 = s.eVar2.replace(/(\?|&)(password=)[^&]*(&|$)/i,"$1$2$3");

And just to give an example, if someone opens url
Then you would open eVar1 report in Adobe Analytics, and would see this value:
Perfect! Yes, another reason why javascript data collection is better than using processing rules.

Btw, after setting up report suite for new website, the first thing I do is to enable two eVars for this and make the javascript (or processing rules) to capture full url-adressess. The best tip for Adobe Analytics, maybe?

About Antti

Digital Analytics Manager specialized in Adobe Analytics, Online personalization, SEO, CRO...

One thought on “Save full page url and referrer url to Adobe Analytics using javascript

Leave a Reply

Your email address will not be published. Required fields are marked *