Google Analytics page view tracking - google-analytics

I am using a shiny dashboard with about 20 pages and recently implemented Google Analytics to track page views. The number of pageviews in GA seems to be the same for all pages. I think that once the home page is hit, all other pages are getting hit as well.
I need help to solve this problem. My GA.js script contains the auto script generated while creating an account with GA and this script.
ga('send', 'pageview', {'title': 'Shiny Dashboard','page': '/#shiny-tab-dashboard'});
I have generated similar lines for all the pages with different 'title' and 'page'. Thanks for helping out.

Google analytics does not record hash parameters by default so you would have to a
change your tracking code
https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#allowAnchor
Below are the changes required
Replace
ga('create', 'UA-XXXXX-Y', 'auto');
with
ga('create', 'UA-XXXX-Y', {'cookieDomain':'auto','allowAnchor': false});

Related

Single Page Application Tracking with Analytics: no virtual pageviews in dashboard

I'm trying to use some virtual pageviews on my single page application (Angular)
I set the js code as follows:
ga('set', 'page', pageviewurl);
ga('send', 'pageview');
where the var pageviewurl could be something like:
'/form/w/toyota?from=hp#step=2__from=js'
But I'm not able to see anything related these virtual pageviews on Analytics dashboard...
am I doing something wrong?
Or in which section of the dashboard can I get pageview data?
Thanks
I answer to my question just to confirm that the js code is correct.
After some time, by accessing to Analytics dashboard, virtual pageview data is visible in the section Real time -> content

Multiple Tracking IDs for Single site without named tracker

In one of my client site, I am seeing multiple tracker IDs without any named tracker. I don't understand why we need multiple tracking IDs for single site?
ga('create', 'UA-XXXXXXXX-1', 'auto');
ga('create', 'UA-XXXXXXXX-2', 'auto');
ga('send', 'pageview')
I'm new to Google Analytics.
You do not need multiple tracking ids for a single site. This is simply an error. The second tracker instance will immediately overwrite the first one, and hits will be recorded for the second property only.

How to view individual page tracking results in Google Analytics

View page tracking results
I have added the Google tracking JS code to each page in my site:
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-xxxxxxx-x', 'auto');
ga('send', 'pageview', '/virtuvalPath/myPageName');
I am getting results from Google Analytics, but the results are summarized for all pages. I want to see the page views for each specific page. How can I view the results for each individual page within Google Analytics?
Thanks.
You can either
Click into each individual page link in the All Pages report, or
Add an advanced filter to filter only for your specific page, or
Create a custom report with the specific page
There are probably other methods but these should be the most direct.

Can I pass google analytics marketing tracking code to a following page (when the landing page doesn't have GA code)

I am in a scenario where we are tagging up on part of the site (purchase.mysite.com) with GA tags but we aren't tagging up the main site (www.mysite.com).
The problem is that a lot of traffic that goes to purchase.mysite.com initially goes via www.mysite.com which means if a user lands on www.mysite.com with a marketing tracking code and then goes to purchase.mysite.com the tracking code will be lost and all traffic from this route will be considered referral.
Is there a way to still pass this marketing campaign code when the user hits purchase.mysite.com (other than adding GA code to the main site which we don't want to do)?
If not possible in GA, is there another technical solution like saving the tracking code in the cookie and then setting it when the user goes to purchase.mysite.com?
Any help would be greatly appreciated.
Thanks,
Frank
Frank,
Your final paragraph htis the nail on the head: save your campaign tracking data into your own cookie and then read this cookie when you're on a page with GA on it and manually set the campaign data. You only need to set it once and it will then propogate through for the whole session/user as per your requirements.
To set the campaign data manually, just use code such as this (ref: https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#campaignName)
ga('set', 'campaignName', 'My Campaign Name');
ga('set', 'campaignSource', 'anotherwebsite.com');
ga('set', 'campaignMedium', 'cpc');
ga('send', 'pageview');
notes
You must set at least Source & Medium for the data to register with GA
Medium has a fixed set of possible values as per this google doc: https://support.google.com/analytics/answer/1033173?hl=en

Google Analytics Cross-Domain Tracking with Multiple Trackers

I have a network of sites that are all on different domains and subdomains (domain1.com, sub.domain1.com, domain2.com, sub.domain2.com). Some of them already have Google Analytics trackers installed. Some do not have GA trackers at all.
I'd like to create a way to see a single GA account for the whole network, across domains, without disrupting existing single-domain GA tracking. Additionally, I need to be able to track visits and conversions across sites in the network as though they were a single site. Basically, you could think of it as a totally separate, independent GA account for the network.
I've seen that it's possible to auto-link domains (https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain#autolink), thereby enabling network-wide analytics and conversion tracking, but is there a way to do this that won't disrupt the existing trackers already on the sites? Perhaps there's a way to make GA create two trackers with different cookies, one of which is cross-domain?
Ideally, I could give each site's developer a snippet of code to add to their site that would enable the network tracking. Is it possible?
Yes, this is possible. A couple of things to keep in mind though:
I have a network of sites that are all on different domains and subdomains (domain1.com, sub.domain1.com, domain2.com, sub.domain2.com). Some of them already have Google Analytics trackers installed. Some do not have GA trackers at all.
This shouldn't be a problem. Its simple to add a second tracker to an existing page. I'll show you how below.
I'd like to create a way to see a single GA account for the whole network
The auto-linker plugin actually only works at the property level, so these will not only have to share the same account, but they'll have to share the same property. But this is probably what you want.
I need to be able to track visits and conversions across sites in the network as though they were a single site. Basically, you could think of it as a totally separate, independent GA account for the network.
Exactly, you'll create a brand new property just for this purpose, to track all four of these "sites" as a single "site".
Perhaps there's a way to make GA create two trackers with different cookies, one of which is cross-domain?
You can create multiple trackers running on the same site, but they must share cookies. This is because analytics.js only stores the client ID in the cookie, and obviously the client is the same.
For one of your existing sites that already has analytics installed, the code probably looks something like this:
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXX-Y', 'auto');
ga('send', 'pageview');
To add another tracker to that page that is tracking a different property, you can just add a few more lines of JavaScript to the snippet. In this example, you're giving your new tracker a the name t2 so it doesn't interfere with the existing tracker.
ga('create' 'UA-YYYY-Z', 'auto', {name: 't2'});
ga('t2.send', 'pageview');
This creates a new tracker and sends a pageview with the new tracker, but it doesn't set up autolinking. To do that you'll have to modify it slightly (assume this code is for domain1.com):
ga('create', 'UA-YYYY-Z', 'auto', {name: 't2', allowLinker': true});
ga('t2.require', 'linker');
ga('t2.linker:autoLink', ['domain2.com']);
ga('t2.send', 'pageview');
And then for domain2.com you'll just have to change the code slightly to autolink to domain1.com:
ga('create', 'UA-YYYY-Z', 'auto', {name: 't2', allowLinker': true});
ga('t2.require', 'linker');
ga('t2.linker:autoLink', ['domain1.com']);
ga('t2.send', 'pageview');
You don't need to list the subdomains because analytics.js tracks those by default.
In addition to the link you provided, here's some more helpful information about cross-domain tracking:
https://support.google.com/analytics/answer/1034342?hl=en

Resources