Expand my Community achievements bar.

SOLVED

track form submission using DTM

Avatar

Level 3

I would like to track the form submission using DTM. If we use event based tracking how can I check if all the form fields are validated before tracking submission button? How these types of logic are added in DTM?

1 Accepted Solution

Avatar

Correct answer by
Level 8

Hi Vidya,

There's a couple of ways you could do this.

You need to ensure that the validation script is loaded before the submit button code. You can create another rule for this or add a sequential third party tag within the same rule

The other (slightly complex-er) method would be to use data elements. This data element will contain the value of the validation script i.e. T or F. Once this data element is set up, you can reference this in your original rule using custom scropt and check the value of the data element to fire your submit button rule accordingly.

I'd suggest trying the 1st method and if it doesn't work, use the 2nd (merely because the 1st one seems a little easier)

Let me know if this helps

Kind Regards

Rahul

View solution in original post

10 Replies

Avatar

Level 3

I need this very urgent. Any help on this is appreciated.

Avatar

Level 8

Hi Vidya,

Sorry for the delayed response.

Please help me out with the details of your validation of the form fields?

As in, what do you mean by validated ? Validated because there is a value in the field ? Validated because there is a green checkbox next to the field ?

Let me know

Rahul

Avatar

Level 3

Hi Rahul,

I want to track the submit button of a form. Before that i want to make sure that all the fields are validated. I mean all the mandatory fields have the proper values added. Only then i can track the submit button. I want to know where can we put that piece of code. 

If you can let me know the standard way of tracking form using DTM would be helpful. Then i can let you know my requirement.

Let me know you need any other information.

Regards,

Vidya

Avatar

Level 8

Hi Vidya,

I understood that you wanted to track the submit button of a form. However, I'm not aware if there's a 'standard' way of tracking forms.

what I need from your end is how exactly you validate the fields in your form. In the sense, if it's a text field do you validate whether the input is present or not or if there's a check box, do you check whether the box is checked or not.

The tracking of the submit button would probably be thru a straight forward event based rule but  validation of these fields would depend on how you'd like to define 'validation'

I hope I'm making sense here.

Please let me know.

Rahul

Avatar

Level 3

Yes , exactly. We do the form validation using javascript. If it is mandatory  text field we check if it has value in it and for check box the box is checked or no and for email if it is in the right email format etc. Everything is done in javascript. Now to track submit button if i use event based rule, how will check if the fields are validated? Else the tracking of submit button doesn't make any scene. Please help me to connect these 2 pieces.

 

Regards,

Vidya

Avatar

Level 8

Right. Got it.

Let me get back to you on this.

Rahul

Avatar

Correct answer by
Level 8

Hi Vidya,

There's a couple of ways you could do this.

You need to ensure that the validation script is loaded before the submit button code. You can create another rule for this or add a sequential third party tag within the same rule

The other (slightly complex-er) method would be to use data elements. This data element will contain the value of the validation script i.e. T or F. Once this data element is set up, you can reference this in your original rule using custom scropt and check the value of the data element to fire your submit button rule accordingly.

I'd suggest trying the 1st method and if it doesn't work, use the 2nd (merely because the 1st one seems a little easier)

Let me know if this helps

Kind Regards

Rahul

Avatar

Level 8

Hi Vidya,

I understood that you're looking to track the 'submit' button. However, there's no 'standard' way of tracking forms

What I'd need from your end is details on how you'd be validating the form. As in, are there text fields on your form that you'd validate for correct input/ input present or if there are check boxes that you'd validate are checked and so on.

Tracking would probably be thru a straight forward event based rule but the complexity arising from your desire to validate can only be addressed if you let me know how you're defining 'validation'

Please let me know if this makes sense.

Kind Regards

Rahul

Avatar

Level 3

Regarding the 1st method, do I need to add validation script in the 3rd party tag?

Avatar

Level 8

That is correct. Have the script added into a 3rd party tag and configure it to fire off before your submit button tracking.