Reputation: 58
Situation
On our site we implement virtual pageviews for ajax filters and page scrollings.
When user open Rent page on our site:
send to GA:
ga("send", "pageview", {page: "/rent/"})
When user scroll to second page:
send to GA (we care only about main page):
ga("send", "pageview", {page: "/rent/"})
Or when user drills down:
send to GA (we care about path):
ga("send", "pageview", {page: "/rent/appartment"})
But we noticed that really GA code does not take current real url (window.location) each time we call ga
, but uses first time location. So when user drill down GA code send:
GET collect?...&t=pageview&dl=http://example.com/rent&dp=/rent/appartment&...
....
Referrer: http://example.com/rent/appartment
Here dl
parameter is location of our page (not really current location) and dp
is a page parameter in ga
call. Notice that referrer is ok.
We decided to provide ga
with real location (like in referrer) and change code to:
ga("send", "pageview", {page: "/rent/appartment", location: "http://example.com/rent/appartment"})
Problem
From now on I was satisfied, but was not guys that uses GA to analyze Paid Search effectiveness: bounce rate raised drammaticaly (something like 20% to 70%).
Drilling to the problem I've noticed that GA "loses" user when we remove campaign parameters (utm...
) and send location without them.
Questions
Should I care about real location in this situation? How does location affects pageviews? How can I workaround or solve this problem?
Additional information
Seems like the main problem is that we drop CPC parameters when we change location
for GA:
Additional information here: https://support.google.com/analytics/answer/1714454?hl=en
But I'm still can't figure out an appropriate solution.
Upvotes: 0
Views: 1426
Reputation: 30431
When you send a hit to GA with analytics.js, it's going to send the data it has stored on the tracker object that you created when you invoked ga('create', ...);
. You can override those values by passing in an object (as you did), but if no overrides are specified, that tracker data is used.
When the tracker object is created it collects data about the current page (e.g. url, title, window size, etc) and stores that information. It does not recollect that info before you send hits. You have to update it if that data changes.
That means if you're updating the page information in an AJAX site and want analytics.js to "remember" that you've updated the page, you'll have to set it on the tracker. The advantage to setting it on the tracker is that if you send other hit types (e.g. events, social, exceptions), you won't have to specify those new values each time.
So, instead of doing:
ga("send", "pageview", {page: "/rent/appartment"})
Do this:
ga("set", {page: "/rent/appartment"});
ga("send", "pageview");
Now, if you send an event later, the event will be associated with the apartment page.
UPDATE: there is now an official guide for how to properly track single page applications with Google Analytics.
Upvotes: 4