<?php
/* ========
This file is being used to simulate an E-commerce sale in Google Analytics based on the users' original cookies. This URL needs to be loaded by the Affiliate Netwerk.
Be careful while testing: deleting E-Commerce sales from Google Analytics can only be achieved by adding the same transaction with negative values (see http://support.google.com/googleanalytics/bin/answer.py?hl=en-GB&answer=72290).
========= */
$username="fashion_test";
$password="0509143335";
$database="fashion_test";
// Settings
//$var_utmhn='fashion-experts.com'; //enter your domain
//$utmac = 'UA-44436624-1'; // Analytics account
$var_utmhn='best-fashion-deals.com'; //enter your domain
$utmac = 'UA-55018676-1'; // Analytics account
$testing = "0"; // 1 = test-mode on (nothing will be send to Google Analytics)
$email = "gdalia.erez@gmail.com"; // To send an email while testing
//mysql_connect(localhost,$username,$password);
//@mysql_select_db($database) or die( "Unable to select database");
// Get required variables from the URL
$subid = "3833313162366334343065623666373131393539383331373963326163323161";
$orderid = "9"; // Order ID - unique ID for the transaction
$total = "9"; //Total and unit price - affiliate fee for the sale
$sku = "9"; // product code
if ($sku == "") {$sku = "1";} // in case you didn't provide any product code It'll just take "1"..
// Get some optional variables from the URL
$storename = $_GET["storename"]; // Affiliation or store name - name of the business your promoting (e.g. "WP4FB")
$tax = $_GET["tax"];
$shipping = $_GET["shipping"];
$city = $_GET["city"];
$region = $_GET["region"];
$country = $_GET["country"];
$orderid = $_GET["orderid"];
$productname = $_GET["productname"];
$category = $_GET["category"];
$utmipc = $sku; // Product code / SKU
$utmipn = $productname; // Product name
$utmipr = $total; // Unit price
$utmiqt = '1'; // Unit quantity
if ($tax != "") {$utmttx = $tax;} else {$utmttx = '0.0';} // Tax
if ($shipping != "") {$utmtsp = $shipping;} else {$utmtsp = '0.0';} // Shipping cost
if ($city != "") {$utmtci = $city;} else {$utmtci = 'na';} // Billing city
if ($region != "") {$utmtrg = $region;} else {$utmtrg = 'na';} // Billing region
if ($country != "") {$utmtco = $country;} else {$utmtco = 'na';} // Billing country
if ($tax != "") {$utmttx = $tax;} else {$utmttx = '0.0';}
$utmp = 'leadtracking.php'; //Page request of the current page (required, no need to change this)
$utmiva = '';
$var_utmn=rand(1000000000,9999999999);//random request number to prevent caching
$var_utmn2=rand(1000000000,9999999999);//random request number to prevent caching
$var_utmn3=rand(1000000000,9999999999);//random request number to prevent caching
$utmhid=rand(1000000000,9999999999);//random request number to prevent caching
// Looks up the original cookie in the DB
//$query= "SELECT * FROM clicks WHERE subid='$subid'";
//$result=mysql_query($query);
/*if (mysql_numrows($result) == 1) {
$utma=mysql_result($result,$i,"utma");
$utmz=mysql_result($result,$i,"utmz");
$utmv=mysql_result($result,$i,"utmv");
$utmx=mysql_result($result,$i,"utmx");
} else {
echo "Subid not found in database.";
exit();
}*/
$utma="91177353.571070991.1413196407.1413209241.1413213333.3";
$utmz="91177353.1413196407.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)";
$utmv="";
$utmx="";
$utmipn = str_replace(" ","%20",$utmipn);
$utma = str_replace(" ","%20",$utma);
$utma = str_replace("|","%7C",$utma);
$utmz = str_replace(" ","%20",$utmz);
$utmz = str_replace("|","%7C",$utmz);
$utmv = str_replace(" ","%20",$utmv);
$utmv = str_replace("|","%7C",$utmv);
$utmx = str_replace(" ","%20",$utmx);
$utmx = str_replace("|","%7C",$utmx);
// Simulates E-Commerce Sale
$transactionUrl ='http://www.google-analytics.com/__utm.gif?utmwv=4.6.5&utmn='.$var_utmn.'&utmhn='.$var_utmhn.'&utmt=tran&utmtid='.$orderid.'&utmtst='.$storename.'&utmtto='.$utmipr.'&utmttx='.$utmttx.'&utmtsp='.$utmtsp.'&utmtci='.$utmtci.'&utmtrg='.$utmtrg.'&utmtco='.$utmtco.'&utmac='.$utmac.'&utmcc=__utma%3D'.$utma.'%3B%2B__utmz%3D'.$utmz.'%3B%2B__utmv%3D'.$utmv.'%3B%2B__utmk%3D'.$utmk.'%3B';
$itemUrl = 'http://www.google-analytics.com/__utm.gif?utmwv=4.6.5&utmn='.$var_utmn2.'&utmhn='.$var_utmhn.'&utmt=item&utmtid='.$orderid.'&utmipc='.$utmipc.'&utmipn='.$utmipn.'&utmiva='.$utmiva.'&utmipr='.$utmipr.'&utmiqt='.$utmiqt.'&utmac='.$utmac.'&utmcc=__utma%3D'.$utma.'%3B%2B__utmz%3D'.$utmz.'%3B%2B__utmv%3D'.$utmv.'%3B%2B__utmk%3D'.$utmk.'%3B';
$urchinUrl ='http://www.google-analytics.com/__utm.gif?utmwv=4.6.5&utmn='.$var_utmn3.'&utmhn='.$var_utmhn.'&utmp='.$utmp.'&utmac='.$utmac.'&utmcc=__utma%3D'.$utma.'%3B%2B__utmz%3D'.$utmz.'%3B%2B__utmv%3D'.$utmv.'%3B%2B__utmk%3D'.$utmk.'%3B';
// Send E-commerce sale to Google Analytics
$testing = "0";
if ($testing == "0") {
$handle = fopen ($transactionUrl, "r");
$test = fgets($handle);
$handle2 = fopen ($itemUrl, "r");
$test2 = fgets($handle2);
$handle3 = fopen ($urchinUrl, "r");
$test3 = fgets($handle3);
fclose($handle);
fclose($handle2);
fclose($handle3);
} else {
// Show's Google Analytics URL's for testing purposes
echo $transactionUrl."
".$itemUrl."
".$urchinUrl."
";
// Send email
$message = $transactionUrl."\n".$itemUrl."\n".$urchinUrl."\n\n Thanks for using Affiliate2Analytics.com!";
mail($email, 'Affiliate 2 Analytics test', $message);
}
//mysql_close();