POST
https://transactions.littledata.io/clientID
This method requires two parameters:
- clientID : user identifier stored by Google Analytics cookie and accessed via the GA tracker object
- cartID : cart token generated by Shopify when an item is added to cart
Littledata’s Shopify script attempts to post this data on the cart page. This works for 95% of Shopify stores, but in custom themes where a user can buy straight from the landing page and checkout it is necessary to post the data to Littledata in callback – after the user has a cart token created but before the user is directed to checkout on another domain.
The data is sent as a JSON object, with the HTTP header set to Content-Type: application/json
. Here is an example of how to POST
JSON to the endpoint using JQuery, after the Shopify cart has been updated.
jQuery.post('/cart/update.js', { updates: { 123456: 1 } }, function(cart) { ga(function() { //wait for ga library var clientID = ga.getByName('littledata').get('clientId'); jQuery.post('https://transactions.littledata.io/clientID', { clientID : clientID, cartID : cart.token //returned from cart update }) }); // continue the redirect to checkout });
This clientID – cartID pair must be sent for every user navigating to checkout, regardless of whether they pay during that session. A 200 HTTP response indicates the clientID and cartID have been accepted.
After the checkout is completed, and Shopify processes the order, Littledata’s server will then match the cartID when the one sent from Shopify’s order web-hook – and so link the Google Analytics web session with the eventual payment.