This is a technical documentation about how to integrate the Lefty Pixel in order to track conversion in Lefty Affiliation feature, using Google Tag Manager.
Setup Lefty Tag
1. Data Layer variables
Define the following variables (or use existing one).
Required :
DL - orderID
β dataLayerlefty.conversion.orderId
DL - orderTotal
β dataLayerlefty.conversion.amount
DL - orderCurrency
dataLayerlefty.conversion.currencyCode
Optional :
DL - products
β dataLayerlefty.conversion.products
2. Create tag
Create a Custom HTML
tag with the following code.
<script>
var products = {{DL - products}};
// products list are optional
if (!products) {
products = [];
}
var orderId = {{DL - orderID}};
var amount = {{DL - orderTotal}};
var currency = {{DL - orderCurrency}};
var ref = {{Page Hostname}};
var url = 'https://a.lefty.io/track?type=conversion'
url += '&orderId=' + orderId;
url += '&amount=' + amount;
url += '¤cy=' + currency;
url += '&ref=' + ref;
if (products.length !== 0) {
var pIds = products.map(function (item) {
return 'pId=' + item.id;
}).join('&');
var pNames = products.map(function (item) {
return 'pName=' + encodeURIComponent(item.name);
}).join('&');
var itemQty = products.map(function (item) {
return 'itemQty=' + item.quantity
}).join('&');
var itemAmount = products.map(function (item) {
return 'itemAmount=' + item.amount;
}).join('&');
url += '&' + pIds;
url += '&' + pNames;
url += '&' + itemQty;
url += '&' + itemAmount;
}
var img = new Image();
img.src = url;
</script>
π‘ Donβt forget to assign a trigger to your tag. (ex: Custom Event purchase
)
Application side
On you shop website, when a user is making a purchase, you should add details of order to your Google Tag Manager dataLayer
.
If you followed the previous example for dataLayer
variable name, it should be as follow.
dataLayer.push({
lefty: {
conversion: {
// STRING
orderId: "ORDER-6423145",
// STRING ex: "USD"
currencyCode: string,
// total price of order (NUMBER)
amount: 2000,
// products list (OPTIONAL)
products: [
{
// STRING. can be product SKU
id: "FWOD234",
// STRING, readable product name
name: "yellow shirt",
// NUMBER, purchased quantity of product
quantity: 2,
// NUMBER, price of a single produce
amount: 100,
},
]
},
},
});
π‘ Then trigger the tag
// Using `purchase` custom event
// or any other event that should trigger the Lefty Tag
dataLayer.push({
event: 'purchase'
});