Mobile app version of vmapp.org
Login or Join
Smith883

: 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

@Smith883

Posted in: #GoogleAnalytics

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?

10.04% popularity Vote Up Vote Down


Login to follow query

More posts by @Smith883

4 Comments

Sorted by latest first Latest Oldest Best

 

@Eichhorn148

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/

10% popularity Vote Up Vote Down


 

@Pope3001725

Try replacing


/#!/


with


/?_escaped_fragment_=/


This worked for me.

10% popularity Vote Up Vote Down


 

@Eichhorn148

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.

10% popularity Vote Up Vote Down


 

@Barnes591

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme