Advertisement:
Pages: [1]
Print
Author Topic: Google Conversion Tracking  (Read 937 times)
0 Members and 1 Guest are viewing this topic.
amain
Newbie
*

Karma: 0
Offline Offline

Posts: 1


View Profile Email
« on: November 06, 2009, 11:13:43 PM »

How do I set-up the subscription form so it works with the Conversion Tracking feature from Google Adwords
Logged
choosethis
Newbie
*

Karma: 0
Offline Offline

Posts: 6


View Profile
« Reply #1 on: March 11, 2010, 07:10:59 AM »

You will need to create an image that you're going to use in the newsletter. Most often a 1x1 pixel image will do the job.  Don't use a background image though as this won't always get through.

You'll need to change or create an .htaccess file. in the directory where the image is. I use something like this

Code:
RewriteEngine On
RewriteRule ^(.*).jpg image.php?$0 [L]

Now for image.php

Code:
<?php

$var_utmac
='UA-XXXXXXXX-1'//enter the new urchin code
$var_utmhn='yourdomain.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_referer=$_SERVER['HTTP_REFERER']; //referer url

$var_utmcsr='ContactManager';  // the campaign source
$var_utmcmd='email';  // the campaign medium
$var_utmccn=$_SERVER['argv'][0];  // the campaign name

$var_uservar='-'//enter your own user defined variable
$var_utmp='tracker/'.$_GET['url'].'.'.$_GET['filetype']; //this example adds a fake file request to the (fake) tracker directory (the image/pdf filename).

$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('.$var_utmccn.')%7Cutmcsr%3D('.$var_utmcsr.')%7Cutmcmd%3D('.$var_utmcmd.')%3B%2B__utmv%3D'.$var_cookie.'.'.$var_uservar.'%3B';

$handle fopen ($urchinUrl"r");
$test fgets($handle);
fclose($handle);

$showit $_GET['url'].'.'.$_GET['filetype']; //this is where the real file should be located

$filename $_SERVER['argv'][0];
header('Content-Type: image/jpeg');

$imageurl fopen($filename"r"); //this is where the real file should be located

while (!feof ($imageurl)) 
{
$image fgets($imageurl4096);
echo $image;
}
fclose($imageurl);

?>


Post Merge: March 12, 2010, 09:35:54 PM
Some servers, and one of my providers does this, don't allow you to fopen a URL, in which case the work around is to create a function at the top of the code as follows:

Code:
function get_content($url)
{
    $ch = curl_init();

    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_HEADER, 0);

    ob_start();

    curl_exec ($ch);
    curl_close ($ch);
    $string = ob_get_contents();

    ob_end_clean();
   
    return $string;   
}

and replace

Code:
$handle = fopen ($urchinUrl, "r");
$test = fgets($handle);
fclose($handle);


with 
Code:
$test = get_content($urchinUrl);

« Last Edit: March 12, 2010, 08:36:55 PM by choosethis » Logged
Pages: [1]
Print
Jump to:  


Advertisement:


Keep this forum up and
running and buy me a beer!