Hi, When any user visited my site I generate clientId and a random unique subid and save both to DB. Then that subid send to affiliate network and they save it with transaction if there will be transaction. Now to add these transactions into Google Analytics E commerce they call one link like this
http://example.com/conversions.php?subid=5b1300507cf376f065062214156d618c&storename=ANKURSTORE&orderid=ANKUR111&total=11.11 by adding necessasry data to link by cron job.
Now when that link called Here is process which happen in that file conversions.php :
1. Get subid and then fetch clientId for that subid from database.
2. Get other details by using $_GET.
3. Add it to Google Analytics by addtransaction and addItem
Here is code of conversion.php :
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//
www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-3970XXXX-Y', '
example.com');
</script>
<?php
$subid = $_GET["subid"];
$orderid = str_replace("#","",$_GET["orderid"]); // Order ID - unique ID for the transaction
$amt = $_GET["total"]; //Total and unit price - affiliate fee for the sale
$num_decimals = (intval($amt) == $amt) ? 0 :2;
$total = number_format($amt,$num_decimals);
$storename = urlencode(str_replace("#","",$_GET["storename"])); // Affiliation or store name - name of the business your promoting (e.g. "WP4FB")
$client_id = $wpdb->get_var("SELECT `ga` FROM `{$table_name}` WHERE `subid` = '{$_GET['subid']}';");
// Function to return the JavaScript representation of a TransactionData object.
function getTransactionJs($ga_array1,$orderid1,$storename1,$total1) {
return <<<HTML
ga('set', 'clientId', '{$ga_array1}');
ga('ecommerce:addTransaction', {
'id': '{$orderid1}',
'affiliation': '{$storename1}',
'revenue': '{$total1}'
});
HTML;
}
// Function to return the JavaScript representation of an ItemData object.
function getItemJs($orderid2,$storename2,$total2) {
return <<<HTML
ga('ecommerce:addItem', {
'id': '{$orderid2}',
'name': '{$storename2}',
'price': '{$total2}',
'quantity': '1'
});
HTML;
}
?>
<script>
ga('require', 'ecommerce', 'ecommerce.js');
<?php
echo getTransactionJs($ga_array,$orderid,$storename,$total);
echo getItemJs($orderid,$storename,$total);
?>
ga('ecommerce:send');
</script>
When this link called by affiliate network it is not adding transactions to Google Analytics. But if we manually run into browser then it works perfectlly.
pls I need help with this issue. I am trying it for couple of days. But didnt find anything and now this group is my last hope.
Thanks in advance. If you need any other info let me know.
Regards,
Ankur