My intention is to capture each line_item on the order success page and push it to an array called rmkt_items
Unfortunately, it comes back null. What am I missing in my code?
Below is the forloop that I am referring to.
var rmkt_items = [];
{% for line_item in order.line_items %}
var item = {
'id': {{ line_item.variant.id }},
'google_business_vertical': 'retail'
};
rmkt_items.push(item);
{% endfor %}
For more context, the code is being used in the dataLayer for Google Ads Dynamic Remarketing. You’ll notice the value ‘google_business_vertical’: ‘retail’. That will be important for the remarketing campaigns that we create.
It looks like I was wrong. I didn’t resolve the issue in my previous reply, but I now have.
Instead of using the order.line_items array within the loop, use the line_items array. To clean up the code, I also used let rmkt_items instead of var rmkt_items, and added in the json filter to the line_item.variant.id
With this new clean up code, I have been able capture all the line items on the order success page into the dataLayer.