basically, my website is based on one set of html codes but it is hosted on 3 different domains. (example.com, example.sg, example.my)
So each of these websites has their unique ids for Google analytics tracking.
Is there a way to tweak the code from Google to track all three websites respectively?
This is the current code I am using.
<script>
(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-38011741-2', 'versafleet.sg');
ga('send', 'pageview');
</script>
It is from here: https://developers.google.com/analytics/devguides/collection/analyticsjs/
The flaw with the code is that it only takes in one id for example.com and there is no where to include the ids for the other 2 websites.
So is there a way to include the ids of the other 2 websites into code to track them as well? Thanks for your help!
You could change your configuration depending on the hostname. Not tested, but it work something like this:
uaids = {
"domain1.com":"UA-XXXXX-X1",
"domain2.sg":"UA-XXXXX-X2",
"domain3.my":"UA-XXXXX-X3",
}
ga('create', uaids[window.location.hostname], window.location.hostname);
ga('send', 'pageview');
where the uaids-Array stores the Account Ids with the respective domain as index and the hostname is pulled via javascript from the location object to retrieve the value.
It would be more reliable to change the account id serverside (but I guess if that where an option you would not have asked).
However in your case it would be simpler to use the same account id for each domain (since apparently the pages are the same) and use view filters based in hostnames to separate the data (update: on second reading I may have misunderstood the requirements).
Unless you expect people to move between the domains and you want to track visitor sessions across domain boundaries - in that case, as already has been pointed out, you would need cross domain tracking (and you should follow Crayons link and get back to us with any problems you encounter there).
Google Analytics uses 1st party cookie tracking. You need to implement cross domain tracking on your pages in order for GA to track the visitor across multiple domains.
Related
I’d like to track certain Webflow events in Google Universal Analytics (using analytics.js) without the use of Google Tag Manager. The specific scenarios we are trying to track are:
PDF downloads
YouTube Video views from lightboxes, sliders and straight embeds
I added the JavaScript tracking snippet to the site-wide Head Code of my site, replacing the UA# with the real one.
<!-- Google Analytics -->
<script>
(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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
Do I just proceed with setting up Event Tracking on a per element basis or do I need to create a tracker?
If you create new trackers they might overwrite configuration options for the first tracker (if any), so that is not only unnecessary but potentially harmful (unless you want to track to different properties, in which case you'd use named trackers that do not interfere with each other).
For your use case you need only the default tracker and then you send an event for the elements the user interacts with.
You might also consider using gtag.js over analytics.js, since Google now gives gtag.js as the default code; documentation is much worse than for analytics.js and there are some doubts that it is feature complete, but Google is unlikely to roll back so I'd say gtag.js is more futureproof.
Gtag.js has some of the advantages of GTM (consistency between tags via the datalayer) without its main disadvantage (arbitrary code injection - GTM has been describes as "XSS as a service"), so it might make sense to go that route now.
I have a Content Management System which let people create websites. the CMS has multiple theme and color schemes which they can choose. Every website created using this CMS has a unique domain (www.abc.com, ww.xyz.com etc).
Product In detail:
I have a website mywebsite.com people can signup there, buy their own domain and create their own website at mywebsite.com. so now they have their own xyz.com website where user can add content from mywebsite.com
All these websites are independent, they just share the same code as they all are using my CMS but they have their own content (pictures, videos, text)
I would like to track the statistics of all these websites all together. It is not a problem if a user goes to abc.com and then goes to xyz.com is counted as different session because they are totally different websites and I want google to count them separately.
I want to do this to check how much views my product is getting as whole. which is the best way to achieve this.
Thank you for your time.
What you're after here is what is referred to as a "roll up" account, this is as standard a feature available in Google Analytics Premium (or 360 as it's now known).
However assuming you don't have the financial resources to drop £100k on a Google Analytics premium account you can achieve similar through double tagging on the same website.
This is fairly straight forward and you can see Google's documentation on this on the link below:
https://developers.google.com/analytics/devguides/collection/analyticsjs/creating-trackers#specifying_fields_at_creation_time
As an example:
ga('create', 'UA-XXXXX-Y', 'auto');
ga('create', 'UA-XXXXX-Z', 'auto', 'rollupTracker');
ga('send', 'pageview');
ga('rollupTracker.send', 'pageview');
Where UA-XXXXX-Z is your property ID for the roll-up account and UA-XXXXX-Y is your users' default tracking code.
Note there are a few caveats to using roll-up views:
Even with cross domain tracking you could end up with more than one session across domains for the same user (if they landed on site A then separately landed on Site B before clicking back to site A)
You could hit the rate limits and sampling limits imposed by Google pretty quicky.
You'll need to use either View filters and/or advanced segments to see the statistics of separate websites and this will only exasperate the issue of sampling limitations.
Detail of the premium Analytics implementation is available over at Luna Metrics:
http://www.lunametrics.com/blog/2015/02/03/rollup-data-google-analytics/
This is a huge ask.
Google Analytics relies heavily on cookies, which are unique to the domain. This means that if Person A is on Site 1, and moves to site 2, your Google Analytics has no way of knowing that that was the same person; they will effectively become a new person every time the domain changes.
Now that's not a problem if you're going to have no links between the sites (although you may want to look into prepending hostnames http://www.lunametrics.com/blog/2015/12/10/basic-google-analytics-filters/#Prepend Hostname to Request URI)
But if you're going to link the sites together then it gets a bit more complicated. You're going to have to set up cross-domain tracking (http://www.lunametrics.com/blog/2015/06/16/cross-domain-tracking-with-google-tag-manager/) on each of these, which is best done using Google Tag Manager. Now depending on your implementation this could be a real headache for you, as this requires the GTM container for each site to have a list that names all of the other sites. This list would need to be updated on every container each time you add a site. However, you can make this significantly simpler if you just go for a straight-up Page View tag, and use the same container on each page.
I am working on a site Local.mensusa.com. which is sob domain of www.mensusa.com.
I added a analytics code to my site but unable to get traffic on my site.
My code:
<script type="text/javascript">
(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-2085156-1', 'auto');
ga('send', 'pageview');
</script>
1: Is this the right code?
2: There is same code pattern for domain and sub domain?
Yes your code looks correct. If you want to be able to compare the data between the Doman and the subdomain then you should use the same tracking code. If you want to keep the data separate ex: two sites that have no relation to each other what so ever, than create a separate account for it.
Possible causes of your problem are.
When did you create the analytics account? it can take 48 - 72 hours for new accounts to begin recording data.
How long ago did you add that code to your site? it can take 24 - 48 hours for new code to start recording data.
Did you check the Real-time report? Standard reports take 24 hours to complete processing.
This tool is also useful for checking that your code is correct. Extension Google Analytics Debugger
It should be the right code. Otherwise, copy/paste it from the dashboard again.
In order to test it, you can easily check if you currently have visitors on your website: go to real time section.
Finally, about subdomain, you have to create another website to watch (with another google code) to track data.
I am currently working on a web app that will be running in an iframe on the webpages of our customers. Now i would like to setup google analytics tracking in a way that i that i can easily distinguish one customer from the other. My plan is to "fake" subdomains, even though it is always the same TLD, so that i can setup a profile for each customer, but still have overall analytics as well.
For example my URL is http://www.domain.com/#/3 where 3 is the customer id. Now i would like to see that in google analytics as 3.domain.com.
Is that possible by doing something like this:
ga('create', 'UA-XXXXXX-1', 'domain.com');
ga('set', 'location', 'http://id.domain.com');
or do i have to go about this in another way? My google analytics knowledge is limited to reading the stats and tracking events and pageviews, so maybe there is a whole different and better way to do this - i am open for suggestions.
Thanks!
It will be much better to use custom variables for this purpose. They give you additional segmentation possibilities on any values and metrics you need, such as customer names or IDs (or both ...)
My site www.katievb.com is a blog hosted by blogspot.com. I've created a Google Analytics account and registered a "Universal Analytics" property. It provided a unique UA ID and some code to embed in the HTML that looks similar to this:
<script>
(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-XXXXXXXX-X', 'katievb.com');
ga('send', 'pageview');
</script>
I did this probably about 24 hours ago. The GA admin page has said "Status: Tracking Not Installed" this whole time. However, GA Real-Time actually does track my visits. (I can use Firefox on a Mac and in real-time see that on the Analytics screen, and then I can go over to a Windows computer with Chrome and visit katievb.com and see that on the real-time screen too.)
In blogspot's settings, I intentionally did NOT populate the Settings > Other > Analytics Web Property ID because it appeared to me that that would expect that I was using the old-style Google Analytics (ga.js) and not this new kind (analytics.js).
Also, I then replicated this in a completely independent pair of blogspot/GA accounts.
Why does it say "Tracking Not Installed"? It seems to be tracking, and I'm not sure what I'm supposed to change about how I installed it.
I've read the instructions many times and have tried different versions of their code and placing it in different locations, such as prior to </head> or </body>.
Eventually it started working. I think it took a day or 2 for the status to accurately reflect that tracking had been properly installed. It's bizarre... because Real-time was working, so I would have guessed that Google's status code would have been able to be updated real-time too.
It takes up to 72 hours to detect, but look in the Reporting section, Standard Reports, under Real Time, and it should show at least 1 active visitors on the site, which is probably you.
You can access to real time tracking.
To see Real-Time data, navigate to the Reporting tab and select Real-Time from the left hand report navigation column.
You will see 1 visitor if there were 1 visitor within the last minute.