Google Tag Manager : Tracking of Ajax actions

Adding an Event on Click
  • You element (form) is loaded through AJAX, after the initial page load.
  • The default action (Click on the button or the link) is stopped (preventDefault()).

Use Case

  • Your name
  • Your Email address
<form id="subscription" name="subscription" action="./" method="POST">
Name: <input type="text" name="Name"><br>
Email: <input type="email" name="Email" required><br>
<input id="buttonToTrack" type="submit" value="Submit">
</form>
<script type="text/javascript">
// When the DOM is fully loaded (jQuery).
$(document).ready(function() {
// Submit the form via ajax.
$("#subscription").ajaxForm();
});
</script>

Tag creation in GTM

Creation of Tag in GTM

Creation of your Data Layout Event Code

<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'popinSubmit'
});
</script>

Creation of the trigger in GTM

Trigger creation into GTM UI

Sources

--

--

--

Swiss Web Developer & Open Source Advocate @antistatique | @Webmardi organizer | Speaker | Author | Drupal 8 Core contributor

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to timeout local session in Flutter, if the application is inactive for some duration?

An image of flutter MaterialApp widget from Flutter starter template

PowerShell script to create resource groups from csv file

KUBERNETES INTERVIEW QUESTIONS AND ANSWERS 2022

How to change last commit message

A Brief History of Priority Queues at CMB

Android example Photo Sharing app

Building my new site with gridsome(vue.js)

Input generators in property-based tests with FsCheck

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kevin Wenger

Kevin Wenger

Swiss Web Developer & Open Source Advocate @antistatique | @Webmardi organizer | Speaker | Author | Drupal 8 Core contributor

More from Medium

Sample Telemarketing Scripts for SOFTWARE

What exactly is the WhatsApp Cloud API?

Fitness Lover to Developer: Building a SmartGym Vision

An API for better EDI and eCommerce