Skip to content

Instantly share code, notes, and snippets.

@alasvant
Last active March 24, 2019 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alasvant/8d019a5323f9a41f19d79740a3c01a60 to your computer and use it in GitHub Desktop.
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.
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