Jump to content

submit button issue with event tracking


toolman

Recommended Posts

Hi there,

 

I have the following code which I would like to use to track click events:

 

 

 <script type="text/javascript">
function trackOutboundLink(link, category, action) {
 
try {

dataLayer.push({'event':'interaction','eventCategory': category,'eventAction':action,'eventLabel': ''});
} catch(err){}
 
setTimeout(function() {
document.location.href = link.href;
}, 100);
}
</script>

 

<input type="submit" name="submit" value="Submit" class="submit-button" onClick="trackOutboundLink(this, 'Contact', 'Signup', 'New Signup');" />

 

However, when the form is submitted, it causes an error by going to a dynamically generated URL. I've been told this is because the setTimeout function is looking for a link, not a button. I have removed the setTimout and the form submits properly.

 

Is there a way I can have the setTimeout function to use an input instead of a link? Or if I just remove the function, will the event still be tracked?

 

Thanks!

 

Link to comment
Share on other sites

You're looking for an href here (in the timeout):

document.location.href = link.href;

 

<inputs> don't have an href attribute.

Here's the input you're passing to your js function:

<input type="submit" name="submit" value="Submit" class="submit-button" onClick="trackOutboundLink(this, 'Contact', 'Signup', 'New Signup');" />

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.