If you are already using Google Tag Manager with a data layer where all your customers data is being pushed to, you can easily integrate the Photoslurp tracking code using GTM.
Please follow the steps below:
1. Add a new custom HTML tag in GTM:
2. Paste in the following code:
<script>
(function() {
var psAlbumId = YOUR_ALBUM_ID_HERE;
var psProducts = {};
var psOrderId = null;
var psCurrency = 'EUR';
for (var i = 0, len = dataLayer.length; i < len; i++) {
var entry = dataLayer[i];
var ecommerce = entry.ecommerce;
if (!ecommerce || !ecommerce.purchase) {
continue;
}
var purchase = ecommerce.purchase;
var products = purchase.products;
for (var j = 0, plen = products.length; j < plen; j++) {
var product = products[j];
psProducts[product.id] = {
count: product.quantity,
price: product.price,
currency: psCurrency
};
}
psOrderId = purchase.actionField.id;
break;
}
window.photoSlurpTrackingSettings = {
products: psProducts,
orderId: psOrderId,
albumId: psAlbumId
};
var d = document,
h = d.getElementsByTagName('head')[0],
s = d.createElement('script');
s.type = 'text/javascript';
s.async = true;
s.src = '//static.photoslurp.com/widget/v3/tracking_notify.js';
h.appendChild(s);
})();
</script>
3. Ensure that your main album ID has been replaced in the code where it says YOUR_ALBUM_ID_HERE.
4. For this example we used the following standard EE dataLayer structure. If your structure is different please adjust the code from step 2 accordingly:
<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
"ecommerce": {
"purchase": {
"actionField": {
"id": "123",
"tax": "14.75",
"shipping": "0.00"
},
"products": [{
"id":"98adsh",
"name":"Converse T-Shirt",
"price":"12.50",
"brand":"Converse",
"category":"Men/Clothing/T-Shirts",
"variant":"red",
"quantity":2
}]
}
}
});
</script>
5. To finish this integration, please choose a trigger that fires once per page on your purchase confirmation page:
If you need any assistance with this setup, please get in touch with our customer support team at support@photoslurp.com with the preview link assigned to your GTM workspace that can be found here: