I am experiencing a very strange problem with Google tag manager (GTM), Google analytics (GA) and Google adwords. So far I am getting nowhere with solving it.
The setup:
We have a singe page application (backbone and marionette) and we are using GTM to push virtual pageviews to GA using standard dataLayer.push events (and also e-commerce events if this is relevant). This setup generally works fine.
The problem:
The problem is users coming from adwords, with a gclid tag. The first pageview for these users is tracked and attributed do the adword campaign correctly, but as soon as they click any link on the site they seem to get a new session in GA, and the original session is then counted as a bounce. All pages are on the same domain, and we have verified that these campaign users are not actually bouncing, they are still on the site but are somehow mislabeled by GA.
I.E.
- The user enters the site with a gclid tag from adwords.
- The visit is tracked as google cpc traffic.
- The user clicks a link in the page, or triggers backbones router.navigate function to load new content.
- The original session from (2) is ended and counts as having bounced, even though the user just followed a link inside the site.
- A new session is created which is not counted as cpc-traffic (since the new page does not have the gclid tag).
Important note: This problem only occurs with campaign visitors! Users without a campaign tag don't get new sessions when they click links.
Has anyone experienced a problem like this before? Is there any special things to take into account when using adwords via GTM on a single page app? What could cause Google analytics to lose track of a session like this?
The site in question is https://fyndiq.se, in a mobile (it uses dynamic serving, the problem is not there on the desktop version which is not a SPA).
Edit - A summary of the problem and the current, imperfect, solution
We have managed to get to an acceptable level with this, but it is far from perfect. Since the solution is all spread out in the comments I thought I would summarize the result here.
The problem is indeed that Analytics creates new sessions for Adwords users, losing track of the campaign. Analytics will start a new session for a user on a few different conditions. The most common are when the user has been inactive for 30 mins, when the user enters the site from a new campaign, and when the user enters the site from a known search engine.
The last two are the issue here. Google judges these condition based on the combination of campaign tags (gclid or utm_) and referrer, and on a single page application referrer does not update!
I.E.
- The users enters www.example.com via adwords. The analytics pageload will have a gclid campaign tag and google as a referrer.
- The user clicks on an internal link and the SPA handles the routing.
- The campaign tag is removed and on a non SPA the referrer would change to www.example.com, but since this is a SPA there has been no real pageload and the referrer remains Google.
- Analytics gets the pageview, sees that the campaign and referrer combo has changed and that the referrer belongs to a search engine, and assumes the user left the page and then re-entered from a search term.
- Analytics starts a new session without the campaign and attributes the session as organic traffic (since it belives the user entered from a google search hit), and the campaign session is a bounce.
To prevent this we ended up doing two things. First we manually send a referrer to Google Tag Manager (if none is sent it defaults to document.referrer, which as said above does not update). On the first pageload we use the real referrer, so that hits get attributed correctly. On any subsequent pageload we send our own domain as referrer, like it would have been on a non SPA. This tells analytics that we are routing internallyand that it should not start a new session.
The referrer can be sent to GTM the same way as you send a virtual pageview url and is (at the moment of writing) set in the same place as url and pagetitle. We make sure this is done on ALL events sent to analytics, not only the pageviews.
The second thing comes from Jareds answer below, we make sure to set page and not just location (see below for why these are different). Page can be set in the advanced settings in GTM. Only one of these two things should be needed, but we did both just to be safe.
This seems to give us mostly correct data. We are still missing about 15% of the cpc transactions compared to the data from adwords but it's hard to know how close to done we really are. Adwords and analytics do not measure the same thing, so a diff is to be expected and the size of the diff will vary from page to page. It is however enough for us to use for testing and marketing, so it will have to do for now.
If anyone finds a solution that is more consistent, please write a new answer!