Expand my Community achievements bar.

DTM How to track changes in the form

Avatar

Level 3

I have a business requirement: when user edits their account details capture the fields in the form that have been changed. 

So, we have the original values of the fields and when user clicks "submit" they should be compared to the new values. if value changed we create a variable with value, e.g. "email changed". Then we combine them into string and map to eVar. 

The code looks like that:

var oldMobileNo = document.getElementById('mobileNumber').value; var oldAnotherNo = document.getElementById('additionalTelephoneNumber').value; var oldEmail = document.getElementById('emailConfirmed').value; document.forms['editContactVO'].onsubmit = function(){ var newMobileNo = document.getElementById('mobileNumber').value; if(oldMobileNo != newMobileNo) { var MobileNo = "mobile number changed"; } else { var MobileNo = ""; } var newAnotherNo = document.getElementById('additionalTelephoneNumber').value; if(oldAnotherNo != newAnotherNo) { var AnotherNo = "additional number changed"; } else { var AnotherNo = ""; } var newEmail = document.getElementById('emailConfirmed').value; if(oldEmail != newEmail) { var Email = "email changed"; } else { var Email = ""; } return MobileNo; return AnotherNo; return Email; } var Final = MobileNo + "," + AnotherNo + "," + Email; return Final;

Then I created Data Element using this code. 

And then my worries started. If I referenced this Data Element from the next page after "submit" it killed all tagging. If I referenced it from event based call on "submit" it also killed the call. Is it possible to capture these values via DTM at all? What could be an alternative route? 

2 Replies

Avatar

Level 5

You can change the expiration of your data element from "page view" to "session" within the UI and the value should persist when you get to the next page.

Avatar

Level 3

It is set to session already but still does not work:(. Actually it kills all calls if it referenced.