Search code examples
google-analyticsenhanced-ecommerce

tracking purshase serverside with curl and enhanced ecommerce


After reading this doc: https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#enhancedecom

I'm trying to send data to google analytics like this :

$data = array(
    "v" => 1,
    "tid" => "XX-xxxxx-x",
    "cid" => "999",
    "t" => "pageview",
    "dh" => "mydemo.com",
    "dp" => "/receipt10",
    "dt" => "Receipt%20Page10",
    "ti" => "T12367",
    "ta" => "Google%20Store%20-%20Online",
    "tr" => 40.39,
    "tt" => 2.85,
    "ts" => 5.34,
    "pa"=>"purshase",
    "tcc" => "SUMMER2013",
    "pr1id" => "P1265445",
    "pr1nm" => "Android%20Warhol%20T-Shirt 2",
    "pr1ca" => "Apparel",
    "pr1br" => "Google",
    "pr1va" => "Black",
    "pr1ps" => 2);

$content = http_build_query($data); 
$content = utf8_encode($content);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://ssl.google-analytics.com/collect");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, utf8_encode($content));
//curl_setopt($ch,CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_exec($ch);
curl_close($ch);

It's partialy working : i've got a hit in the real time view, and i can see the page in the "all page" view, but nothing in the ecommerce view.

what i'm missing?


Solution

  • You will need to wait. It takes 24 - 48 hours for the data to show up in the standard reports. Its still being processed.

    If its working in realtime then you will probably see it tomorrow under ecommerce.