• Hi,

    Been using contact form 7 for months now, however we have recently noticed that the event tracking code has now become obsolete. So we have tried implementing the new code but it does not seem to be working when we using live view.

    Can anyone give some recommendations or help us understand whether it is working?

    Many thanks.

Viewing 2 replies - 16 through 17 (of 17 total)
  • @gracy834

    I got it. But I ran into a few more issues I wanted to recap in case someone else has a similar issue. So if I just use the script/code as is:

    var wpcf7Elm = document.querySelector( '.wpcf7' );
    wpcf7Elm.addEventListener( 'wpcf7mailsent', function( event ) {
        dataLayer.push({'event' : 'Form Submitted'});
    }, false );

    …I get a “Uncaught TypeError: Cannot read property ‘addEventListener’ of null”.

    And if I check it exists with an IF first…

    var wpcf7Elm = document.querySelector( '.wpcf7' );
    if(wpcf7Elm){
    wpcf7Elm.addEventListener( 'wpcf7mailsent', function( event ) {
        dataLayer.push({'event' : 'Form Submitted'});
    }, false );
    }

    I squash that null error, but the dataLayer push isn’t firing.

    So I went back to document…

    document.addEventListener( 'wpcf7mailsent', function( event ) {
            dataLayer.push({'event' : 'Form Submitted'});
        	}, false );

    And that fired my GTM trigger. There’s a bit of a delay (maybe 3 minutes), but GA did finally register the event on today.

    @creativekindle

    Glad that you fixed it, got to love a workaround.

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Event Tracking in Google Analytics’ is closed to new replies.