I'm pushing a simple ecommerce object to the Google Tag Manager dataLayer
on the client side. It's working fine but I need to move this to the server.
I found the Google API Node.js Client Library but it's still pretty young and I'm not able to find any working examples.
Has anyone managed to do this? How would I accomplish the following using the google-api-nodejs-client in node.js?
dataLayer.push({
event: 'purchase',
user: 'user_1234',
transactionId: 'trans_123',
transactionAffiliation: 'Acme Clothing',
transactionTotal: 11.99,
transactionProducts: [
{
id: '1234',
sku: 'SKU47',
name: 'Fluffy Pink Bunnies',
price: 11.99,
quantity: 1
}
]
});
I don't think you need the google API for this or that library. You can just use the Google Measurement Protocol.
Here's an example of how they build the call.
So for your datalayer post, it will be something like:
For the transaction
v=1 // Version.
&tid=UA-XXXXX-Y // Tracking ID / Property ID.
&cid=1234 // user_1234.
&t=transaction // Transaction hit type.
&ti=123 // transaction ID. Required.
&ta=acmeClothing // Transaction affiliation.
&tr=11.99 // Transaction revenue.
Then the item hit
v=1 // Version.
&tid=UA-XXXXX-Y // Tracking ID / Property ID.
&cid=1234 // Anonymous Client ID.
&t=item // Item hit type.
&ti=123 // Transaction ID. Required.
&in=fluffy pink bunnies // Item name. Required.
&ip=11.99 // Item price.
&iq=1 // Item quantity.
&ic=sku47 // Item code / SKU.