I'm not a coder though I've learned alot from this board. My friend set up a template for me to work from. there is 2 versions of google anaylatic script in there and i'm not sure which to use?
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
e=o.createElement(i);r=o.getElementsByTagName(i)[0];
e.src='//www.google-analytics.com/analytics.js';
r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
ga('create','UA-XXXXX-X','auto');ga('send','pageview');
</script>
or....
<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-XXXXX-X', 'auto'); ga('send', 'pageview'); </script>
Thanks so much!
As per the comments, the answer is: leave one with the correct GA Id. Remove any of them in the head tag, and leave the final snippet before closing the body tag.
Related
Google Goal conversion not working when I download pdf.
Here I followed following steps:
<html>
<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-XXXXXX', 'auto');
ga('send', 'pageview');
</script>
<a href="/wp-content/uploads/2017/03/SEO-ebook-Final.pdf" onClick="javascript:_gaq.push(['_trackPageview','/wp-content/uploads/2017/03/SEO-ebook-Final.pdf']);">Ok<a/ class='bold-uppercase'>
</html>
gaq.push us classic Google analytics code as in ga.js. Your Google Analytics snippet shows you are using analytics.js which is universal analytics.
So basically you are mixing things you shouldn't be.
<script>
/**
* Function that tracks a click on an outbound link in Analytics.
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label. Setting the transport method to 'beacon' lets the hit be sent
* using 'navigator.sendBeacon' in browser that support it.
*/
var trackOutboundLink = function(url) {
ga('send', 'event', 'outbound', 'click', url, {
'transport': 'beacon',
'hitCallback': function(){document.location = url;}
});
}
</script>
You'll also need to add (or modify) the onclick attribute to your links. Use this example as a model for your own links:
Check out example.com
code ripped from Track outbound links
for my static HTML webside I embedded this recommended script code to every page of the side.
<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-96597161-1', 'auto');
ga('send', 'pageview');
ga('set', 'userId', {{USERID}});
The question is:
how to format my known Google analytics userId into this place {{USERID}}?
Is it With brackets?, with quotes?
Thanks for your help.
The analytics.js fields reference lists UserID as format type "text", which means you pass it in like you would any other string value in Javascript (i.e. in as quoted string).
In fact the same page has examples:
// Set the user ID when creating the tracker.
ga('create', 'UA-XXXX-Y', {'userId': 'as8eknlll'});
// Alternatively, you may set the user ID via the `set` method.
ga('set', 'userId', 'as8eknlll');
So i have Universal Analytics code with multiple trackers:
<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', 'auto');
ga('create', 'UA-yyyyyyyy-y', 'auto', {'name': 'second'});
ga('send', 'pageview');
ga('second.send', 'pageview');
</script>
How do i create Cross Domain tracking since UA-yyyyyyyy-y profile is used to gather info from 2 separete domains. With one tracker it is pretty simple:
<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-yyyyyyyy-y', 'auto', {'allowLinker': true});
ga('linker:autoLink', ['other-domain.com'] );
ga('send', 'pageview');
</script>
But what do i do wen i have 2 trackers, how do i set up cross domain tracking for this Universal Analytics profile: UA-yyyyyyyy-y? If you answer my question you will also answer a part of this question:
http://stackoverflow.com/questions/20126897/google-analytics-cross-domain-tracking-with-multiple-trackers
In your example with just a single tracker, you're missing the call to require the linker plugin. Without that it won't work. Perhaps that is the source of your issue.
Regardless, in analytics.js you can call any method on any tracker by simply prefixing the method name with the tracker name. You'll notice your first example already does this in the line ga('second.send', 'pageview').
So, to implement auto-linking on both trackers you'd do something like this:
ga('create', 'UA-yyyyyyyy-y', 'auto', {allowLinker: true});
ga('require', 'linker');
ga('linker:autoLink', ['other-domain.com'] );
ga('send', 'pageview');
ga('create', 'UA-yyyyyyyy-y', 'auto', {name: 'second', allowLinker: true});
ga('second.require', 'linker');
ga('second.linker:autoLink', ['other-domain.com'] );
ga('second.send', 'pageview');
Notice the second. prefix on all the method calls in the second block which corresponds to the name "second" that I gave the tracker.
For more information on the auto-linker plugin, check out this resource:
https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain#autolink
And for more information on the various methods and method signatures, here is the guide:
https://developers.google.com/analytics/devguides/collection/analyticsjs/method-reference
I'm trying to use analytics.js with JW Player. Page view works and I can send my own events. However I am not seeing the JW events for Video Plays, Video Completes, and Seconds Played such as I used to get with previous version of the player using the older GA script.
I have read JW's docs but I don't see what I'm doing wrong. Thanks for any help.
<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-34936065-2', 'auto');
ga('send', 'pageview');
</script>
<script>
ga('send', 'event', 'This is an Event Category', 'An Action Type', 'An event label' );
</script>
</style>
<script src="http://jwpsrv.com/library/7QL57lXFEeKkiSIACp8kUw.js"></script><script>jwplayer.key="iE4DX1FvqagyymuKRD+RHWzV5OVPIjQx13H8Mg==";</script><div id='mediaplayer'></div>
<script type='text/javascript'>
jwplayer('mediaplayer').setup({
file: 'http://content.jwplatform.com/videos/vM7nH0Kl-640.mp4',
ga: { }
});
</script><br />
To use JW Player google analytics plugin you need premium/ ads/ enterprise edition.
You're using Pro edition.
We have this code on the website.
<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-40584814-1', 'webistename.com');
ga('send', 'pageview');
</script>
How can I add another account to it? Can I add something like this?
Can I add something like 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-40584814-1', 'webistename.com');
**ga('create', 'UA-472147-1', 'webistename.com');**
ga('send', 'pageview');
</script>
I tried that and I can't see the stats on the new account. How can I achieve this? I know I could invite someone via an email but I want to add a completely new account.
Thanks!
Since you're using Universal Analytics (not the original Async version), you have to pass it within the create statement via the options object:
ga('create', 'UA-XXXXXX-X');
ga('create', 'UA-XXXXXX-Y', 'auto', {
'name': 'foo'
});
// later on...
ga('send', 'pageview'); // sends to account XXXXXX-X
ga('foo.send', 'pageview'); // sends to account XXXXXX-Y
The documentation
Asynchronous tracking code my friend ;)
https://developers.google.com/analytics/devguides/collection/gajs/?hl=pl#MultipleCommands