: GA tracking utm query params after hashbang We currently use a hashbang for the portion of our site that generates dynamic content which can also be deep linked. Our analytics team wants to
We currently use a hashbang for the portion of our site that generates dynamic content which can also be deep linked. Our analytics team wants to use utm params to track the referral traffic from social networks. We are using Universal Analytics (analytics.js) as well as GTM.
Will GA pick up the query parameters after the hashbang or does it always have to go before? For example:
example.com/#!/some/content?utm_source=foo&utm_campaign=bar
example.com?utm_source=foo&utm_campaign=bar/#!/some/content
In #1 , I'm concerned that the utm params won't be recorded and in #2 the page will break or the url could be incorrectly written. How does GA pull in those parameters - location.search? regex?
Can I get away with using either?
More posts by @Smith883
4 Comments
Sorted by latest first Latest Oldest Best
I used this:
JavaScript
ga('create', 'UA-XXX-X', {'allowAnchor': true});
ga('send', 'pageview', { 'page': location.pathname + location.search + location.hash});
After implementing this, anchor style URLs appear along side normal pages in Analytics reports.
Found on:
mediacause.org/track-anchor-tags-google-analytics-2/
I ran into this same issue at a previous company and it was a mess (one guy actually lost his job due to bad URLs being used for tracking paid search and no one understanding why GA showed different results than Kenshoo...).
You can come up with a custom workaround using JavaScript to inspect the URL query string to look for UTM params after a #! then rewrite the page that gets tracked.
If you decide to go the route of custom JavaScript to deal with it this may be useful. Here is the reference for setting the various UTM values on your own in code.
So without adding custom JavaScript or rewriting the system to remove the hashbangs, there really isn't a way to deal with this. Honestly though you should do whatever you can to move away from #! URLs.
I dont think the GA will kick-in after #!
I guess (and correct if my speculation is wrong), that your #! site is using the front controller pattern (just like WordPress and its index.php).
In which case, can't you tweak your framework to move away from #! and towards something more friendlier? Your problem is that # generally indicates anchor tags within the page. So, anything which comes after the # is not interpreted separately.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.