0

I am trying to add Event Tracking to a FreeForm submit button so that when the user clicks the button it tracks the event in Google Analytics.

The problem I am running into is that regardless of how I try formatting the onClick event, it keeps getting stripped out.

Here's what I have tried:

{freeform:submit attr:class="btn btn--active" attr:value="Send" attr:data-ng-hide="formSent" attr:onClick="ga('send', 'event', { eventCategory: 'Contact', eventAction: 'Form', eventLabel: 'Project'});" }

And this:

{freeform:submit attr:class="btn btn--active" attr:value="Send" attr:data-ng-hide="formSent" attr:onclick="ga('send', 'event', { eventCategory: 'Contact', eventAction: 'Form', eventLabel: 'Project'});" }

Finally I just removed all of capitalization:

{freeform:submit attr:class="btn btn--active" attr:value="Send" attr:data-ng-hide="formSent" attr:onclick="ga('send', 'event', { eventcategory: 'contact', eventaction: 'form', eventlabel: 'project'});" }

Regardless the outcome is always the same:

<input type="submit" name="submit" value="Send" class="btn btn--active" data-ng-hide="formSent">

As you can see, the onClick code is completely removed. Any ideas on what I am doing wrong?

2
  • Have you considered making the GA call from jQuery on click? – AllInOne Dec 22 '14 at 20:43
  • No I haven't. I am not that skilled of a developer so I went for the easier route. – Doug Dec 22 '14 at 20:49
1

As a work around you could consider using jQuery with Google Analytics, something like:

$('input').on('click', function() {
  ga('send', 'event', { eventcategory: 'contact', eventaction: 'form', eventlabel: 'project'});
});

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.