Iulian Boiculese
Iulian Boiculese

Reputation: 373

How to set country location for google analytics?

I have next code:

function get_pixel_tracking(){

  $utm_source = $_GET['utm_source'];
  $utm_medium = $_GET['utm_medium'];
  $utm_campaign = $_GET['utm_campaign'];  

  $var_utmac = 'UA-XXXXXXXX-Y'; //enter the new urchin code
  $var_utmhn = 'example.com'; //enter your domain
  $var_utmn = rand(1000000000,9999999999); //random request number
  $var_cookie = rand(10000000,99999999); //random cookie number
  $var_random = rand(1000000000,2147483647); //number under 2147483647
  $var_today = time(); //today

  $var_utmp = '/page-gapx';

  $urchinUrl = 'http://www.google-analytics.com/__utm.gif?utmwv=1&utmn='.$var_utmn.'&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn='.$var_utmhn.'&utmp='.$var_utmp.'&utmac='.$var_utmac.'&utmcc=__utma%3D'.$var_cookie.'.'.$var_random.'.'.$var_today.'.'.$var_today.'.'.$var_today.'.2%3B%2B__utmb%3D'.$var_cookie.'%3B%2B__utmc%3D'.$var_cookie.'%3B%2B__utmz%3D'.$var_cookie.'.'.$var_today.'.2.2.utmccn%3D'.$utm_campaign.'%7Cutmcsr%3D'.$utm_source.'%7Cutmcmd%3D'.$utm_medium.'%3B%2B__utmv%3D'.$var_cookie.'.%3B';

  $im = file_get_contents($urchinUrl);
  header('content-type: image/gif');
  echo $im; 
}

When I call this function, google analytics is tracking but the Location Country from Google Analytics is always the server location not the user location.

How can I get the correct locations(i.e. Country, City) in Google Analytics?

Upvotes: 1

Views: 1395

Answers (1)

vly
vly

Reputation: 316

There is no way to pass the end-user's IP or Geolocation (derived by GA from IP) neither through that or through the measurement protocol at this stage.

Location dimensions aren't available for output in Filters either.

Your best bet is to geomatch the IPs yourself and push them as custom vars/dimensions yourself (have a look at MaxMind's self-hosted or API solutions).

Upvotes: 0

Related Questions