1

I'm having trouble passing Google Analytics parameters on link clicks. It seems that the problem is that the new page opens before the parameters are picked up. This leads to a red line in httpfox "ns binding error".

From SO and Google it seems the solution is to use setTimeOut with a 1,000ms delay.

Within Google-Tag-Manager I have the following custom html:

 <script>

    $('.submit-incident.clearingfix a').click(function(event){

        dataLayer.push({
            'event':'GAevent',  
            'eventCategory': 'Report Submit', 
            'eventAction': 'Link Click', 
            'eventLabel': 'CTA'
        });
    });
</script>

I'm not actually sure how to integrate setTimeOut without simply delaying the whole thing by 1 second.

This didn't work.

<script>
    setTimeOut($('.submit-incident.clearingfix a').click(function(event){
        dataLayer.push({
            'event':'GAevent',  
            'eventCategory': 'Report Submit', 
            'eventAction': 'Link Click', 
            'eventLabel': 'CTA'
        });
    });),1000);
</script>

And even if it did it wouldn't make sense to me. How would I delay the page opening for a second so that Google Analytics has enough time to pick up the dataLayer parameters?

1 Answer 1

2

One possible approach:

$('.submit-incident.clearingfix a').click(function(event){
    dataLayer.push({
        'event':'GAevent',  
        'eventCategory': 'Report Submit', 
        'eventAction': 'Link Click', 
        'eventLabel': 'CTA'
    });
    var target = this.href;
    setTimeout(function() { location.assign(target); }, 1000);
    event.preventDefault(); 
});

In other words, instead of delaying the invocation of the whole event handler (that doesn't make sense indeed - you need to wait for push to go through only), you delay the page changing process (setting the timeout on location.assign call).

Sign up to request clarification or add additional context in comments.

1 Comment

thanks @raina77ow I'm going to accept the answer shortly because it does exactly what I asked - delays the page opening while allowing the analytics parameters through. However it does not work.This must be a Google Analytics issue. I even tested by setting a 5 second delay. I see the parameters appear in httpfox and Google Tag Assistant. The nsbinding error is no longer there but using real time analytics on a particular page it doesn't appear to be coming through.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.