How to Use ECU and Google Analytics

datePosted on 10:57, October 21st, 2009 by Jason
Share

We have been asked about if ECU can be integrated with Google Analytics, and we featured the following post on the A4U Forum, but  I thought we’d pop it here too (note this is only available for Pro members who have a fair knowledge of PHP):

There is a way to send your unit click information to google analytics, Ive not tested this method myself yet though.

In your ‘My Details’ page, enter the ‘Callback URL’ value.
an example url:

http://www.mydomain.com/myscript.php?unitid=[UNIT_ID]&product=[PRODUCT_TITLE]&datetime=[CLICK_TIME]

This url should point to a small PHP script that sits on your own website (I’ll get to that in a minute).
Within the callback url, you can specify which information you want to send to the PHP script. Other parameters are listed in the dropdown help for the Callback URL.

When a click occurs, we send that specified information to your PHP script, which then forwards it to google analytics.

This is the PHP script that I have found that should do the trick:
Google Analytics without Javascript – PHP – Snipplr

There are 3 lines that you will need to edit within the PHP script:
PHP Code:

$var_utmac=GOOGLE_ANALYTICS_CODE; //enter the new urchin code
$var_utmhn=WEB_DOMAIN; //enter your domain

The other line is where you will place any value/values that you want to send to google:

PHP Code:

$var_uservar=$storeinfo["storeid"]; //enter your own user defined variable

You could replace the $storeinfo["storeid"] part with any of the values that we have sent to the script, ie
PHP Code:
$var_uservar=$_GET['product_title'];
or:
PHP Code:

$var_uservar=$_GET['unit_title'].’:’.$_GET['product_title'];

This probably sounds more convoluted than it actually is, but its the only way that I’ve found that could work.

Good luck

Here is the full PHP script:
PHP Code:

$var_utmac=GOOGLE_ANALYTICS_CODE; //enter the new urchin code
$var_utmhn=WEB_DOMAIN; //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_referer=$_SERVER['HTTP_REFERER']; //referer url

$var_uservar=$storeinfo["storeid"]; //enter your own user defined variable
$var_utmp=”http://”.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

$urchinUrl=’http://www.google-analytics.com/__utm.gif?utmwv=1&utmn=’.$var_utmn.’&utmsr=-&utmsc=-&utmul=-&utmje=0&utmfl=-&utmdt=-&utmhn=’.$var_utmhn.’&utmr=’.$var_referer.’&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(direct)%7Cutmcsr%3D(direct)%7Cutmcmd%3D(none)%3B%2B__utmv%3D’.$var_cookie.’.’.$var_uservar.’%3B’;

$handle = fopen ($urchinUrl, “r”);
$test = fgets($handle);
fclose($handle);
?>

Let us know how you get on, and if you have any changes/improvements for this we can share with our other users

  • Facebook
  • Twitter
  • Sphere
  • Sphinn
  • StumbleUpon
  • LinkedIn
  • Delicious
  • Share/Bookmark
affiliate marketing
categoryPosted in Tutorial | printPrint
Related Posts:

4 Responses to “How to Use ECU and Google Analytics”

  1. Adam on February 8th, 2010 at 8:32 pm

    Has this code been tested? I’m not great at php but I thought anything after // would be commented out, meaning the URLs wouldn’t work?

  2. Jason on February 8th, 2010 at 10:32 pm

    Hi Adam

    This has been tested and works fine. The // in the ‘code’ are there to comment out the help text in each line. For example:

    var_utmac=GOOGLE_ANALYTICS_CODE; //enter the new urchin code

    would mean that you enter your urchin code in place of the GOOGLE_ANALYTICS_CODE

    Hope that makes it clearer for you.

  3. Tony on February 13th, 2010 at 7:02 pm

    Does the website field need to have http:// or not. Cheers

  4. Jason on February 16th, 2010 at 3:21 pm

    Hi Tony

    Yes indeed, the full URL for the callback page is required.

Leave a Reply

Name: (required)
Email: (required) (will not be published)
Website:
Comment: