2

I'm setting up Google Tag Manager on e-commerce store where is a lot of brands.

I need to make trigger on Floodlight script when is specific products in purchase.

So I made trigger where is detected general purchase event and when is this general event detected I enabled function "Some Custom Events" and add Custom JavaScript variable which will detect if the specific brand is in order and push to datalayer event "brandPurchase". Then I added condition if contains "brandPurchase".

My trigger:

But thus trigger is applied on every thank you page even is not the specific product in order

Javascript script which detect if needed brand is in order:

function() {
    function getFromDataLayer(key) { 
        var result = null; 
        dataLayer.push(function() { 
            var value = this.get(key);
            if (value) {
                result = value;
            }
        });
        return result;    
    };
      
    var ecom = getFromDataLayer('ecommerce.purchase.products')
    var filterValue = "Krups"
    
    var filteredProducts = ecom.filter(function (val) {
        return val.brand.includes(filterValue);
      }
    )
      
    if(filteredProducts > 1) {
        dataLayer.push({event: 'brandPurchase'})
    }
}

How I can achieve ti have applied trigger only if specific brand is in order?

1
  • If you want help, you should show your own debugging of this code on your thank you pages.
    – BNazaruk
    Sep 4, 2022 at 17:27

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy