Reputation: 23
Hello I am having some problems to configure my experiment for analytics. I am having trouble because I havent diferent urls, I just have diferent jsp pages to display. So for example I have the following: www.mysite.com/search (it points to search1.jsp) and www.mysite.com/search (it points to search2.jsp)
PS:www.mysite.com/search is just a example
But the url to access both pages are the same (www.mysite.com/search). I handle how page will be displayed from controller.
I have done as follow to configure my experiment: http://postimg.org/image/6nqs3omft/ (added url to image since I am not able to post images here)
and I have added the following javascript code to my jsp variation page 1:
<script src="//www.google-analytics.com/cx/api.js?experiment=xXxxXXXxxXXxxXXXxX"></script>
<script>
cxApi.setChosenVariation(1);
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-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>
I have two question about it, synce I am not getting results from google.
1 - Is it right? when user access this page google will understand that user is inside experiment 1?
2 - Need I use the code provided by google when I a create my experiment? Or just this javascript code is enought? and if is necessary add the google code, need I to add it to all my pages?
Thanks a lot.
Upvotes: 0
Views: 144
Reputation: 23
user3669154 thanks for you help, but the code generated from google is not necessary =) That code is just necessary when you dont want take care about redirecting and etc. If you are doing it on server side just the following code on cliente side works:
<script src="//www.google-analytics.com/cx/api.js?experiment=xXxxXXXxxXXxxXXXxX"></script>
<script>
cxApi.setChosenVariation(VariationNumberThatYouAreShowing);
</script>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-xxxxxxxx-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>
Upvotes: 0