Vaibhav Dhage
Vaibhav Dhage

Reputation: 902

google analytics counts double visits for on single page

I am using google analytics for the first time

here is the code which I have added

<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');
 console.log("executed");
  ga('create', 'UA-46680625-1', 'wfihotspotnet.in');
  ga('send', 'pageview');
</script>

I also want to add custom variables to google analytics script, I got the code from one source , which is.

<script type='text/javascript'>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-46680625-1']);

// set custom variables
_gaq.push(["_setCustomVar", 1, "Member", "yes", 1]);

_gaq.push(["_setCustomVar", 3, "Topic", "JavaScript", 3]);

// track page view
//_gaq.push(['_trackPageview']);
console.log("executed");
(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 thought its because I have added these two scripts together, but after removing 2nd script also it shows same result 2 vsits/sometimes 3. is there any way to add custom variables and google analytics code together in single code.

Upvotes: 1

Views: 296

Answers (1)

Nick Blexrud
Nick Blexrud

Reputation: 9603

You are using new analytics.js code with old ga.js code. Are you attempting to migrate to universal analytics? If so, use their migration.

Upvotes: 2

Related Questions