How to Use ECU and Google Analytics

by Jason on October 21, 2009

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:[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:
PHP Code:


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


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

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


Adam February 8, 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?

Jason February 8, 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.

Tony February 13, 2010 at 7:02 pm

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

Jason February 16, 2010 at 3:21 pm

Hi Tony

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

Zac Zheng May 15, 2010 at 4:49 pm

I have just implemented this and hoping that it works!

There’s an important issue with the callback url configuration. Since it’s configured at account-level and not per unit(or group), only ONE domain can be used.

Many people I’m sure use ECU across multiple websites so this really needs to be resolved.

callback_url per group would probably work best. Per unit, if able to be saved in template, will also be OK.

I’ll fire off a support ticket now.

Comments on this entry are closed.

Previous post:

Next post: