AJAX Listener
for Google Tag Manager

Push AJAX events to data layer

Download GTM container or copy the ajax listener tag


A GTM tag that pushes data from AJAX forms into data layer.

This is an upgraded version of a widely used Lunametrics AJAX listener. Lunametrics’ version of the script has been working very well over the years, but with the rise of the Single Page applications (SPAs) the script oftentimes doesn’t work. It is usually caused by missing jQuery library that Lunametrics’ script depends on.

This script works without any dependencies and should work for all websites.

More info in FAQ

Get Started

How to configure new GTM account

There are 2 options you can use to integrate the script.

Option 1: Import tags and variables using our container script (suggested).

Importing a container script is the quickest way to get started. It will automatically create a custom HTML tag with all the required variables into your GTM account for you to use.

  1. Download container file
  2. Open your account in Google Tag Manager and navigate to Admin -> Import Container.
  3. Choose the downloaded file and select Existing workspace.
  4. ⚠️ Set Choose an import option to Merge with Overwrite conflicting tags, triggers and variables.
    Merging containers will make sure your existing tags, triggers and variables will stay in place and you won’t lose any of your previous configuration.
  5. See that you have 1 new tag and 13 new variables.
  6. Confirm the import and see the custom HTML tag and variables in your workspace.

🔗 View more detailed import guide

Next learn how to use AJAX listener.

Option 2: Configure a custom HTML tag and variables manually.

More advanced users can set up the tag and variables themselves without using the pre-built script.

  1. Copy the script
  2. Create a custom HTML tag, name it “AJAX Listener”. Paste the script to HTML input field and set the tag to trigger on All Pages
  3. Use the Analytics Mania tutorial to set up custom variables.

How to switch from Lunametrics AJAX listener

Differences between Lunametrics listener and this script are minimal and switching them shouldn’t take more then a minute.

All GTM variables that were working with Lunametrics keep working as is and there’s no need to change any of them. The only thing you need to do is replace the custom HTML tag with this script. Once this is done then everything should work as it did before.


Why doesn’t Lunametrics script work?

Lunametrics depends on a javascript library called jQuery. This means that if your website developers haven’t included jQuery in the website code then Lunametrics ajax listener script will not work.

This problem is more common with Single Page applications.

The easiest way to find out if your website has jquery enabled is to ask the developers. Another option is to use a browser console

This script is dependency free and should work regardless of what technology the website is built with.

How to use AJAX Listener

The tag is modified from a frequently used Lunametrics script. Everything that works with Lunametrics tag will keep working the same way.

Once the script is configured in GTM then use the following tutorials on how to use it:

Leave a comment if you have any questions or feedback

by Marko Sulamägi