Reputation: 295
I would need to apply the same dataLayer to multiple sites that are using the same ecommerce system. Rather than copying/pasting the exact same DL onto multiple sites, I was thinking of pushing to the dataLayer withing a Custom HTML Tag in the GTM console.
Is that something specific you would recommend doing or not doing?
As a reference this is my DL:
var impressions = [];
var i, len;
var date1 = new Date();
var date2 = new Date(abe_searchParams["arrivalDate"]);
var timeDiff = Math.abs(date2.getTime() - date1.getTime());
var leadDays = Math.ceil(timeDiff / (1000 * 3600 * 24));
for (i = 0, len = abe_roomRatesData.length; i < len; i++) {
impressions.push({
'name' : abe_roomRatesData[i]['roomCode'] + "-" + abe_roomRatesData[i]['rateCode'],
'id' : abe_roomRatesData[i]['rateCode'],
'price' : abe_roomRatesData[i]['totalRate'],
'category' : abe_roomRatesData[i]['roomCode'],
'variant': abe_searchParams["iataNumber"],
'metric1' : leadDays,
'metric2' : abe_roomRatesData[i]['totalRate'],
'metric3' : abe_searchParams['numberOfNights'],
'metric7' : abe_roomRatesData[i]['totalRate'] / abe_searchParams['numberOfNights']
});
}
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'event' : 'addtoCart',
'metric6' : leadDays,
'ecommerce' : {
'currencyCode': abe_hotelInfo["hotelCurrency"],
'impressions' : impressions
}
});
Thx
Upvotes: 0
Views: 1588
Reputation: 1515
I would advise against this as a best practice. Pushing things onto the dataLayer in a custom HTML tag can be misleading for any future developers who will work on the code of the website as it will be very difficult for them to identify where the actual push is happening in the code.
If you want to implement GTM on several e-commerce sites, then your e-commerce platform should usually have some sort of templating system that allows you to build a GTM template of some sort that gets loaded by all the sites. This would be the cleaner approach.
Upvotes: 4
Reputation: 8736
You can definitely do that if you will be able to maintain it. And there is nothing wrong with if you will place this code in custom HTML tag
Upvotes: 2