Last active
March 24, 2019 14:52
-
-
Save alasvant/8d019a5323f9a41f19d79740a3c01a60 to your computer and use it in GitHub Desktop.
Sample code for creating custom Episerver Forms form container block. This is the sample avaScript to get the data-* attribute values when form is submitted.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof $$epiforms !== 'undefined') { | |
$$epiforms(document).ready(function myfunction() { | |
$$epiforms(".EPiServerForms").on("formsSubmitted", function (event) { | |
if (event.isFinalizedSubmission && event.isSuccess) { | |
// we have our custom dataLayer object, we could also have this code somewhere: window.dataLayer = window.dataLayer || []; and then use that | |
if (typeof dataLayer !== 'undefined') { | |
var currentForm = $$epiforms(this).get(0); | |
// using dom native methods, to support wider range of browsers that don't support the 'dataset' | |
var categoryName = currentForm.getAttribute("data-gtm-formcategory"); | |
var formName = currentForm.getAttribute("data-gtm-formname"); | |
console.log('Form submitted, GTM dataLayer values, category name:[' + categoryName + '] form name:[' + formName + ']'); | |
dataLayer.push({ | |
'event': 'formSubmission', | |
'formCategory': categoryName, | |
'formName': formName | |
}); | |
} | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment