I have the below product string on purchase which currently works fine. I would like to add currency events and merchandising eVars. How can I add a sample event to the below logic?
I want to add event 1=2.3 and eVar25=”caps” for example
try {
var productString = [], cleanProductString
for (i=0; i<adobeDataLayer.length; i++) {
if (adobeDataLayer[i].event == 'purchase') {
var tmp = i;
for (j=0; j < adobeDataLayer[tmp].transaction.orderItems.length; j++)
{
productString.push(";"+adobeDataLayer[tmp].transaction.orderItems[j].productSKU+";"+adobeDataLayer[tmp].transaction.orderItems[j].quantity+";"+adobeDataLayer[tmp].transaction.orderItems[j].price.toFixed(2));
}
s.products = productString.toString();
}
}
} catch(e) {}
Solved! Go to Solution.
Views
Replies
Total Likes
First of all please read this documentation: https://experienceleague.adobe.com/docs/analytics/implementation/vars/page-vars/products.html?lang=e...
the syntax of s.products is
s.products = "category;product name;unit, total price; events;merchandisign eVars"
For merchandising eVars you need to first configure the eVar to have correct configuration. https://experienceleague.adobe.com/docs/analytics/implementation/vars/page-vars/evar-merchandising.h...
Make sure to choose the product syntax if you want to use as part of s.products
Based on your code you just need to add 2 more categories separated by a ";"
try {
var productString = [],
cleanProductString
for (i = 0; i < adobeDataLayer.length; i++) {
if (adobeDataLayer[i].event == 'purchase') {
var tmp = i;
for (j = 0; j < adobeDataLayer[tmp].transaction.orderItems.length; j++) {
productString.push(";" +
adobeDataLayer[tmp].transaction.orderItems[j].productSKU +
";" +
adobeDataLayer[tmp].transaction.orderItems[j].quantity +
";" +
adobeDataLayer[tmp].transaction.orderItems[j].price.toFixed(2) +
";" +
"event1=2.3" +
";" +
"eVar25=caps"
);
}
s.products = productString.toString();
}
}
} catch (e) {}
Please be aware that you can add more than one event and one more than one eVar but they will need to be separated by a pipe "|".
You can omit event but you will still to keep the placeholder for events using ";;"
Also the above logic is only good if event and eVar apply to each individual products, however if you want to use it at the global level like shipping price for all products and not for individual products then you should us the merchandising conversion syntax (you will need to configure evar to use this syntax).
Code will look as follow:
try {
var productString = [],
cleanProductString
for (i = 0; i < adobeDataLayer.length; i++) {
if (adobeDataLayer[i].event == 'purchase') {
s.events += "event1=2.3"
s.eVar25 = "caps"
var tmp = i;
for (j = 0; j < adobeDataLayer[tmp].transaction.orderItems.length; j++) {
productString.push(";" +
adobeDataLayer[tmp].transaction.orderItems[j].productSKU +
";" +
adobeDataLayer[tmp].transaction.orderItems[j].quantity +
";" +
adobeDataLayer[tmp].transaction.orderItems[j].price.toFixed(2)
);
}
s.products = productString.toString();
}
}
} catch (e) {}
Firstly, your code for traversing adobeDataLayer looks cumbersome and possibly incorrect (from an ACDL perspective). I suggest that you use adobeDataLayer's event listener: https://github.com/adobe/adobe-client-data-layer/wiki#addeventlistener
Back to your question:
You didn't mention if your eVar25 and event1 should be fixed to those values. But assuming that you're able to get the correct values, then you would set your s.products string according to the required syntax: https://experienceleague.adobe.com/docs/analytics/implementation/vars/page-vars/products.html?lang=e...
Views
Replies
Total Likes
First of all please read this documentation: https://experienceleague.adobe.com/docs/analytics/implementation/vars/page-vars/products.html?lang=e...
the syntax of s.products is
s.products = "category;product name;unit, total price; events;merchandisign eVars"
For merchandising eVars you need to first configure the eVar to have correct configuration. https://experienceleague.adobe.com/docs/analytics/implementation/vars/page-vars/evar-merchandising.h...
Make sure to choose the product syntax if you want to use as part of s.products
Based on your code you just need to add 2 more categories separated by a ";"
try {
var productString = [],
cleanProductString
for (i = 0; i < adobeDataLayer.length; i++) {
if (adobeDataLayer[i].event == 'purchase') {
var tmp = i;
for (j = 0; j < adobeDataLayer[tmp].transaction.orderItems.length; j++) {
productString.push(";" +
adobeDataLayer[tmp].transaction.orderItems[j].productSKU +
";" +
adobeDataLayer[tmp].transaction.orderItems[j].quantity +
";" +
adobeDataLayer[tmp].transaction.orderItems[j].price.toFixed(2) +
";" +
"event1=2.3" +
";" +
"eVar25=caps"
);
}
s.products = productString.toString();
}
}
} catch (e) {}
Please be aware that you can add more than one event and one more than one eVar but they will need to be separated by a pipe "|".
You can omit event but you will still to keep the placeholder for events using ";;"
Also the above logic is only good if event and eVar apply to each individual products, however if you want to use it at the global level like shipping price for all products and not for individual products then you should us the merchandising conversion syntax (you will need to configure evar to use this syntax).
Code will look as follow:
try {
var productString = [],
cleanProductString
for (i = 0; i < adobeDataLayer.length; i++) {
if (adobeDataLayer[i].event == 'purchase') {
s.events += "event1=2.3"
s.eVar25 = "caps"
var tmp = i;
for (j = 0; j < adobeDataLayer[tmp].transaction.orderItems.length; j++) {
productString.push(";" +
adobeDataLayer[tmp].transaction.orderItems[j].productSKU +
";" +
adobeDataLayer[tmp].transaction.orderItems[j].quantity +
";" +
adobeDataLayer[tmp].transaction.orderItems[j].price.toFixed(2)
);
}
s.products = productString.toString();
}
}
} catch (e) {}
Thank you so much.. This is very helpful. This really helped me to get unstuck
Views
Replies
Total Likes
Views
Likes
Replies
Views
Like
Replies
Views
Likes
Replies
Views
Likes
Replies