Thursday, 21 June 2018

Google analytics, users

I have had Google analytics on my webpage for about three years now.
My page is very specific, it's written in Swedish.
My potential users are about 1000 persons, 1500 at most.

Previous years Google analytics have shown what I assume is correct data.
Looking at May previous year it shows 332 users.
May this year 12287 users.
And that is not in any way possible.

If I look at where my users are from it's 99.89 from Sweden meaning it's not Google analytics "spam".

I have have not changed anything in the code since 2016-ish.

Is there anything in the JavaScript code that needs to be changed to get correct results?

I have added some custom dimensions to the JavaScript.

UserId is a calculated number that originated from the users IP.
Maybe this is tin foil hat theory, but is this due to GDPR?
Or can something be changed to make it correct?

as php code

if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip=$_SERVER['HTTP_CLIENT_IP'];
}elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip=$_SERVER['REMOTE_ADDR'];
}
$ip=str_replace(".","",$ip)*2;

if (isset($_COOKIE['Hoppvader'])){
    $Cookie = "Y";   
    $no = count(explode(",", $_COOKIE['Hoppvader']));
}else {
    $Cookie = "N";   
    $no = 0;
}

?>
<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',{ 'userId': '<?=$ip;?>' }, 'auto');

  ga('require', 'linkid', 'linkid.js');
  ga('require', 'displayfeatures');
  ga('send', 'pageview', {
      'dimension1':  '<?=$ip;?>',
      'dimension2':  '<?=$Cookie;?>',
      'dimension3':  '<?=$no;?>'
    });

</script>

In 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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-xxxxxx',{ 'userId': '1574427072' }, 'auto');

  ga('require', 'linkid', 'linkid.js');
  ga('require', 'displayfeatures');
  ga('send', 'pageview', {
      'dimension1':  '1574427072',
      'dimension2':  'Y',
      'dimension3':  '15'
    });

</script>


Bounty edit:

I have added a dashboard page for you to see my data.
http://www.hoppvader.nu/Stats.html
As you can see there is a massive spike in users over from one day to another.
If you want any other data please just ask and I will try to add it as soon as possible.

I also added php and javascript tags in case that is part of the problem.
Php for generating the javascript tag used to send the data to GA.



from Google analytics, users

No comments:

Post a Comment