Wednesday, July 20, 2016

PHP - google analytics ecommerce tracking from server side

Create a new Analytics account

Open google.com/analytics, click the Sign in to Analytics button [top right (Google Analytics) ], and follow the instructions.

Enable eCommerce in your reports

Sign in to your Analytics account.
Navigate to the desired account, property and view.
In the VIEW column, select Ecommerce Settings.
Click the Enable Ecommerce toggle ON.
Optional: Click the Enable Related Products toggle ON.
Click Next step.
Click Submit.

Google analytics integration with PHP (server side)

Download the Server Side Google Analytics class from github. Click here to download.Extract the files in your project folder. In case of laravel, copy the files in the project public folder

 Usage - Ecommerce tracking

<?php

 include(public_path().'/ss-ga.class.php'); [public path - Laravel public directory ]

     

$ssg_1 = new ssga( '<Your GA tracking id>','<Site name>' );

//$transaction_id, $affiliation, $total, $tax, $shipping, $city, $region, $country
$ssg_1 ->send_transaction("11111111", "Insurance", 500, 12, 0,"", "", "");

$ssg_2 = new ssga( '<Your GA tracking id>','<Site name>' );
//$transaction_id, $sku, $product_name, $variation, $unit_price, $quantity
$ssg_2->send_item("11111111", "222222", "TEST-INSURANCE", "", 50, 4);

?>

1 comment:


  1. Hello,

    we provide affordable and result-oriented SEO services, please give a chance to serve you.


    Thanks
    Admin: E07.net

    ReplyDelete