we try to set up experiments in our site. We would like to testing 3 type of banner on our home page.
1. If anybody click on the banner, makes event, which si set up as a goal in GA. This goal measure clicking correctly.
2. We implement code for measuring experiments and made javascript function for changing banners, they changing well.
3. For set up whole experiments in GA and in code we follow this documentation: https://developers.google.com/analytics/solutions/experiments-client-side
Finnaly our whole GA script on site looks this:
<script src="//www.google-analytics.com/cx/api.js?experiment=sTe5dJkJTfmSO8YXsc7Kuw">
<script>
var variation = cxApi.chooseVariation();
cxApi.setChosenVariation(variation);
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
(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 type="text/javascript" src="http://oursite.cz/js/ga.js"></script>
<script type="text/javascript">
_gaq.push(['_trackPageview']);
</script>
Problem is, that experiment does not work. It does not measure anything. When we try to look on console, what data are sending, we realize, that ` correctly send hash Te5dJkJTfmSO8YXsc7Kuw, but that is all, There is no data of variation type, which was choosed by
<script>
var variation = cxApi.chooseVariation();
cxApi.setChosenVariation(variation);
</script>
It should sent 0 or 1 or 2, but it send nothing. What we make wrong? Thank you for answer,
You're missing the closing tag when loading the content experiment.
You have:
<script src="//www.google-analytics.com/cx/api.js?experiment=sTe5dJkJTfmSO8YXsc7Kuw">
Should be:
<script src="//www.google-analytics.com/cx/api.js?experiment=sTe5dJkJTfmSO8YXsc7Kuw"></script>
Related
I paste the code just before in every webpage and it doesn´t work.
Can somebody check why?
My website is http://www.agriculturacanaria.com
It has html, asp and css files. I didn´t touch the css but the code is already in all the head section of both the two others.
I don't know if that's valid GOogle Analytics cdode. It may be an old way or something, but the modern code looks something 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>
You can probably use that code block and put in your own UA code and get it to work.
Microsoft Word makes for a really bad HTML editor, so you may want to find an alternative that allows for greater flexibility over the code and less bloat of the HTML. (You're probably being penalized for a tactic called "keyword stuffing" alone.)
Hope this helps!
I am trying to setup event tracking for file downloads in Google Analytics. After some research I added the following code to the link that needs to be tracked:
<a onclick="_gaq.push(['_trackEvent','Download','PDF',this.href]);" href="http://www.link.com/file.pdf" target="_blank">Link Text</a>
The following code is on the page for Google Analytics:
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-9999999-1");
pageTracker._trackPageview();
} catch(err) {}
</script>
This has been active for over 48 hours but I'm not getting events in GA. It says that "13 of your visits sent events" but displays no other information. Any ideas?
It looks like you're mixing two different APIs for Google Analytics.
The first snippet you posted is for the ASYNC tracking but you have used the (now legacy) traditional tracking in the second snippet.
To get it working change your page tracking code to look like this, the other code looks OK.
<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>
More details here:
https://developers.google.com/analytics/devguides/collection/gajs/asyncTracking
If you are Migrating to Async Tracking, the following link can guide you - https://developers.google.com/analytics/devguides/collection/gajs/asyncMigrationExamples
I have portal which behaves like multiple portal.
The portal code base is same but for all sites but content is based on which url or domain you came across.
Currently i am able to track my domain
example.com
and also subdomains like
a.example.com, b.example.com
. But i want to also track
anotherexample.com
which also point to same domain. How can I do?
Any suggestions?
multiple url pointed to same code base. It does not matter. The only matter is the url above and the tracking code in site is matching or not. So you have to take google access code from database which just write in address bar.
Codes:
<!-- Google Analytics -->
<script type="text/javascript">
var accountNameFromDB = ...Some Operations...
var domainNameFromDB = ...Some Operations...
var _gaq = _gaq || [];
_gaq.push(['_setAccount', accountNameFromDB]);
_gaq.push(['_setDomainName', domainNameFromDB]);
_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>
Just take accountNameFromDB and domainNameFromDB variables dynmically.
Add this code head of master page(or main template) or add every page.
I have been trying to setup a custom variable for the past few days and it hasn't been working.
My Google tracking code is part of a master page (asp.net concept) so I can't set the custom variable inside the second script block labeled "Async Google Code" because it is shared by many other sections.
Below is my code and the order it appears in my page. Is there any way I can set it outside the "Async Google Code" script?
<head>
<!-- Setting Custom Var -->
<script type="text/javascript">
$(function () {
_gaq.push(['_setCustomVar', 1, 'Account', 'UserType', 2]);
}
</script>
<!-- Async Google Code -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-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>
</head>
wrap your custom variable stuff in a function to be called and insert a call to that function between the var _gaq... and _trackPageview lines in the bottom piece.
Your "setting custom var" code is missing an end bracket.
You need to set the custom variable before track pageview. You have the custom var in the jQuery document ready shortcut, making it so that it happens after the trackpageview.
I have ecommerce tracking set up on my site and in google analytics. The problem is that sometimes it tracks the e-commerce sales but sometimes it doesn't.
Here is the code which is being output before my closing body tag:
<!-- BEGIN GOOGLE ANALYTICS CODE -->
<script type="text/javascript">
//<![CDATA[
var _gaq = _gaq || [];
_gaq.push(["_setAccount", "UA-2795368-10"]);
_gaq.push(["_trackPageview", "/checkout/onepage/success/"]);
(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';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
//]]>
</script>
<!-- END GOOGLE ANALYTICS CODE -->
<script type="text/javascript">
//<![CDATA[
_gaq.push(["_addTrans","100000029","","10.0000","0.0000","0.0000","asa","","GB"]);
_gaq.push(["_addItem","100000029","12","Test Item","","10.0000","1.0000"]);
_gaq.push(["_trackTrans"]);
//]]></script></div>
One of the advantages of async Google Analytics is that you can put it at the top of the page.
Google recommends putting it at the top of the body, not the bottom. Your intermittent tracking may be due to people leaving the page before the tracking beacon has been sent. This could be fixed by putting the code higher in the page.
http://code.google.com/apis/analytics/docs/tracking/asyncTracking.html#Installation
Your code looks good otherwise. It would be help if you posted the live URL though.