-
Notifications
You must be signed in to change notification settings - Fork 3
/
tag-rocket-product-id-change.html
44 lines (36 loc) · 1.76 KB
/
tag-rocket-product-id-change.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<script data-cfasync="false">
/*
Web Site Advantage: Tag Rocket Product ID change [v1.0]
Change the ID sent to different tags
https://bigcommerce.websiteadvantage.com.au/tag-rocket/articles/tag-rocket-api/
Copyright (C) 2023 Web Site Advantage
*/
!function(w,t){
w[t]=w[t]||{};var T=w[t];T.i=T.i||[];if(!T.init)T.init=function(f){T.i.push(f)};
T.init(function() {
T.on('GetValue',function(data, eventName){
// destination = GA4, GoogleAds, MicrosoftAds, FacebookAds, PinterestAds, YahooAds
// type = ItemId (variant, e.g. when added to a cart), ItemGroupId (product, e.g. category page), VariantName
// itemGroupIdFormat = format set in the app
// itemIdFormat = optional format set in the app
// for the VariantName type a default variantFormat is provided instead
// value = set to the initially calculated value, you can change it
// item = information about the relevant product
// type = OrderAmount. supported by destinations GoogleAds, MicrosoftAds, FacebookAds, GA4, PinterestAds, TwitterAds, YahooAds. includes order. defaults to order.orderAmount
// rewrite how a specific id is sent
switch(data.destination + data.type) {
case "GA4ItemGroupId":
data.value = data.item.productId + '-' + data.item.currency;
break;
}
// trim long ids as they get rejected by some tags
switch(data.destination) {
case "GoogleAds":
case "MicrosoftAds":
data.value = data.value.slice(0, 50);
break;
}
});
})
}(window,"TagRocket")
</script>