More than a question, I want to give back to the community...
Here is a little snippet for a code that will help you guys push the submission of forms to the dataLayer in Google Tag Manager.
I noticed that there were explanations of how to push to the dataLayer, but there were no actual examples. So here it is. I'd recommend narrowing down the querySelector if you have more than 1 form on the same page, but even with that, it will help.
If anyone of you pros wanna suggest anything that'd work better so that people can see this thread just comment below:)
`
<script>
var inputs = [];
var inputs = document.querySelectorAll('input');
var dictionary = {};
var x = inputs.forEach(function(field) {
var key = field.getAttribute("name");
var value = field.value;
dictionary[key] = value;
});
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'event': 'formInfoPush',
'ObjInfo': dictionary});
</script>
`
Many issues with that code.
Finally, the real issue people have with form tracking is the trigger. Not grabbing content of the fields. And it's a good practice to push the form identifier to the dataLayer on the submission/attempt/error events instead of all the fields.
You're attempting to make a universal solution to a way-too-general problem. As a result, you don't really achieve much.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.