2
votes

I have function which pushes clicked link attributes to dataLayer for Google tag manager.

https://developers.google.com/tag-manager/enhanced-ecommerce

Problem is that extension "adguard" has ability to block such tracking. In adguard it calls 'A filter for all known counters and analytical systems'. While blocking dataLayer.push, it blocks eventCallback event too and link doesn't get opened.

Here is function:

function ga_promoTriggerClick(e)
{
    var p_id = $(e).attr("data-id");
    var p_name = $(e).attr("data-name");
    var p_creation = $(e).attr("data-creation");
    var p_pos = $(e).attr("data-pos");

    dataLayer.push({
        'event': 'promotionClick',
        'ecommerce': {
            'promoClick': {
                'promotions': [
                    {
                        'id': p_id,
                        'name': p_name,
                        'creative': p_creation,
                        'position': p_pos
                    }]
            }
        },
        'eventCallback': function()
        {
            var p_href = $(e).attr("href");
            if(typeof p_href != "undefined")
            {
                document.location = $(e).attr("href");
            }
        }
    });
}

How can i send user to link if "adguard" is blocking the dataLayer.push?

Some thoughts:

  • Error / Success / Fail function, but none of them exists.
  • Set timeout 1 second ( this way user will have 'lag' )
  • Check if adguard is turned on ( somehow ) and on click check the variable

Thanks for suggestions

1
Have you tried renaming dataLayer to something else?vinoaj
Just tried it ( developers.google.com/tag-manager/devguide#renaming ) , didn't helped. Same result - blocks "callback" event.Roman Losev

1 Answers

3
votes

Solution which worked for me is pretty simple. All i needed is to check if tag manager works.

<script type="text/javascript">
window.addEventListener('load', function()
{
    if(window.ga && ga.create) 
    {
        console.log('Google Analytics is loaded');
    } 
    else 
    {
        console.log('Google Analytics is not loaded');    
    }

    if(window.google_tag_manager)
    {
        console.log('Google Tag Manager is loaded');
    }
    else
    {
        console.log('Google Tag Manager is not loaded');
    }
}, false);
</script>

Solution was found here: https://marthijnhoiting.com/detect-if-someone-is-blocking-google-analytics-or-google-tag-manager/