my old ga.js code is:
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-1']);
_gaq.push(['_setDomainName', 'mywebsite.com']);
_gaq.push(['_trackPageview']);
(function(){
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
after I upgrade to new analytics.js code 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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXX-1', 'auto');
ga('send', 'pageview');
I notice that my pageview is decreasing about 30% ~ 50%,
and bounce rate is increasing about 130%
the obvious difference syntax between old and new is:
_gaq.push(['_setDomainName', 'mywebsite.com']);
as far as I know, actually there is no sub domain site,
I guess maybe the old analytics data is incorrect,
and the new analytics data is correct?
is there anyone can explain why the analytics data change so big?
or what am I doing wrong with?
Related
I got a website builder app where users can create their own sites.
Each customer points his domain to the app's ip which has its own UA code to collect data and show page views statistics in the back office. In addition, if customer got his own Google Analytics account he may indicate it and start tracking data.
The current frontend ga.js code looks like this:
<script type="text/javascript">
var _gaq = _gaq || [];
/* app UA code */
_gaq.push(['x._setAccount', 'UA-XXXXXXX']);
_gaq.push(['x._setDomainName', 'customersdomain.com']);
_gaq.push(['x._setAllowLinker', true]);
_gaq.push(['x._trackPageview']);
/* customer's UA code */
_gaq.push(['_setAccount', 'UA-YYYYYY']);
_gaq.push(['_trackPageview']);
(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(ga, s);
})();
</script>
Now I need to migrate to Universal Analytics but I am not sure what code should I use. I've done plenty of searches but I am still doubting. Would the following code work?
<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-XXXXXXX', 'customersdomain.com');
ga('create', 'UA-YYYYYYY', 'customersdomain.com');
ga('send', 'pageview');
</script>
You need a named tracker. You can set this up in the configuration object that can be passed as the third parameter instead of a cookie domain (in that case the cookieDomain setting goes into the configuration object). Plus you need two send pageview calls, one for each tracker.
<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-XXXXXXX', {
'name' : 'mycustomtracker',
'cookieDomain' : 'customersdomain.com'
});
ga('create', 'UA-YYYYYYY', 'customersdomain.com');
ga('mycustomtracker.send', 'pageview');
ga('send', 'pageview');
</script>
I have spent quite a lot of time researching ways to use GA on a locally run file, but not using http://localhost:(some_port).
Every method I use never returns any regular data. This is the closest I have got to receiving anything:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-47519364-1']);
_gaq.push(['_setDomainName', 'none']);
_gaq.push(['_setAllowLinker', 'true']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/u/ga_debug.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Anyone got this working in this fashion before?
Thanks for enlightening my eyes with the option of the '_debug.js' script.
I am using the analytics module and had the same problem.
So I used the debug script and got the following error when trying to send an event:
Unallowed document protocol. Aborting hit.
I googled it and found this thread exlaining how to bypass it:
https://productforums.google.com/forum/#!topic/analytics/KNz8TimivXo
This was the answer:
ga('create', 'UA-**********-6', {'cookieDomain': 'none'});
ga('set', 'checkProtocolTask', function(){ /* nothing */ });
ga('send', 'pageview');
i am using google analytics to track my site. They said to add a tracking.js code to my site in every page to track the site. For which i made a google_analytics.js file, wrote the code there and included this file in everypage i need to track. But Google Analytics page is saying that track is not installed!
Google analytics provide this service through two js - ga.js and another is analytics.js
For ga.js, you need to write following code in each html page of your site -
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
if you are using analytics.js, you need to write below code in each page of your site -
<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-XXXX-Y');
ga('send', 'pageview');
</script>
please see this link for more info -
How do i use both for an existing google acc that has been using ga.js...i cant seem to find the right documentation. anyone with experience in this?
To expound what Pete says.
Create a new web property for analytics.js
- In your google analytics account, go to Admin section and Create a new web property
- Creating a new property will provide you with a new Tracking ID
Dual Tag
- Add both your ga.js and analytics.js tracking code. Note that they must not share the same UA code. Your codes may look something like below:
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxx-y']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<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-z', 'yoursite.com');
ga('send', 'pageview');
</script>
Existing ga.js users should create a new web property for analytics.js and dual tag their site. It is perfectly safe to include both ga.js and analytics.js snippets on the same page.
see
https://developers.google.com/analytics/devguides/collection/analyticsjs/
The ga.js code will be obsolete in a couple of years, i suggest you migrate to Universal analytics. The initial phase has probably started by non.
After setting up Google analytics for the first time I went to Admin > Tracking Code:
So apparently this is Universal Analytics given to me.
<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('send', 'pageview');
</script>
I can't find my asynchronous tracking code (which would look like this):
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Am I only supposed to use one?
Do they both go right before </head>?
As universal is in beta, I would continue using ga.js tracker on your primary web properties.
If you want to try out the new functions (e.g. custom dimensions/metrics) of Universal, you can create a new property specifically for it.
Also, to simplify deployment, try Google Tag Manager.