This recipe was originally posted by Lunametrics.
This recipe listens for $.ajax requests to come back successful and publishes data about each request into the data layer. Perfect for firing tags after a successful AJAX-style form submission or when AJAX-requested resources are available.
This recipe is for a listener only. It has no visible effect on your site and does not send data to Google Analytics or other tools unless you create additional triggers and tags to do so.
Instructions
- Download Container File
Download the container JSON file (right-click on the link and click “Save Link As” or “Save Target As” to save the JSON file to your computer). - Import JSON File into GTM
Log into your own Google Tag Manager container and head to the Admin section of the site. Under Container options, select Import Container. Read this blog post for more details about importing a container file. - Preview & Publish
Use the Preview options to test this container on your own site. Try testing each of the events to make sure they’re working properly. If everything looks good, go ahead and publish! - Need more information?
Not sure where you can use this recipe? Read the following two blog posts: Free AJAX Event Listener for Google Tag Manager (by Lunametrics) and AJAX Form Tracking with Google Tag Manager (by me)
View all 40+ Google Tag Manager Recipes