-
Notifications
You must be signed in to change notification settings - Fork 0
/
wp form tracking by google tag managerwordpress
106 lines (57 loc) · 1.7 KB
/
wp form tracking by google tag managerwordpress
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# WP Form Submission Event
Events Name GA4 = generate_lead
Additional Parameters = formId
cHTML Tags on Tag manger
=========================
<script>
// This code notifies Google Tag Manager when a wpForm is submitted
var elementsArray = document.querySelectorAll('[id^="wpforms-form-"]');
elementsArray.forEach(function(elem) {
elem.addEventListener("submit", function(e) {
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
event: "wpFormSubmit",
wpFormElement: event.target
});
});
});
</script>
Triggering === ✅ All Pages
Variable
1. wpFormId
-----------
function() {
var field = {{wpFormElement}}.elements.item(0) //First element of form
return field ? field.value : undefined;
}
2. wpFormInput0
----------------
function() {
var field = {{wpFormElement}}.elements.item(0) //First element of form it's like an array 0,1,2,3,4 use like this
return field ? field.value : undefined;
}
3. wpFormAction
---------------
function() {
var formAction = {{wpFormElement}}.action;
return formAction ? formAction : undefined;
}
4. wpFormElement
----------------
Data layer Variable
5. custom javascript
________________-----
function() {
'use strict';
// your code here
return document.querySelector(".className").innerText.replace('€', '').replace(',', '.');
}
6. using Custom javascript variable by input box name
-----------------
function() {
return document.getElementsByName('input_box_name')[0] ? document.getElementsByName('input_box_name')[0].value: '';
}
if this document is helpful for subscribe my channel for more upcoming videos.
CEO - Founder
TrackingbyGTM
https://wlo.link/@trackingbygtm