Note from Unbounce
This script + tutorial will show you how to track “Add To Cart” button clicks as events with Google Tag Manager, when using Shopify’s Buy Button. You’ll also learn how to send those events back to Google Ads and Facebook Ads. This handy script was created by Community legend and Unbounce Expert @Jonathan. If you have any questions about this script, please reach out him directly or tag him in the comments section below.
A large part of turning more browsers into buyers is ensuring that not only are you putting the right content in front of your audience, but also that you’re able to track events accurately. As you may already know, a first-time product viewer is quite different from a 3rd-time product viewer who added a product to their Cart.
In ecomm, many advertisers decide to skip the cart entirely. In that case, the Add To Cart button takes you straight to the checkout page. This means you need to track any button clicks on Add To Cart and send that information back to Google and Facebook.
This gets even more tricky when using a Shopify Buy Button, since in reality, the Buy Button is a script in an iframe. In this post, we’ll show you how to track “Add To Cart” button clicks as events with Google Tag Manager, when using Shopify’s Buy Button. We’ll also show you how to send those events back to Google Ads and Facebook Ads.
READ THIS FIRST
Use Unbounce’s Script Manager to add Google Tag Manager’s script
Use Unbounce’s Script Manager to add Google Analytics’ script
Step 3: Configure GTM:
3.1 Enable important variables
By enabling these variables we can then see a variables value once an event is triggered. It was not needed for this demonstration but it is good practice to do so in case a user would want to create another event using a variable’s value. A variable’s value can be seen in the preview and debug mode.
3.2 Create a conversion linker tag
Conversion linker tags are used to help tags measure click data so that conversions are measured effectively.
Important step for anyone using the Shopify Buy Button. GTM does not recognize it as a button, since in reality, it’s an iframe. Therefore, we need to help them recognize it.
Define a custom event called “click to purchase”
The point of the code was so that we can create an event when someone clicks on the “add to cart” button. The “add to cart” button is in an HTML element, which means GTM can’t identify it as a button. We edit the script so an event would trigger.
4.2 Replace the string on line 9 with your own div id. This div id can be found on Line 1 of your Shopify Buy Button script, in the iframe.
Step 5: Create the click to purchase trigger
This trigger needs to be created in order to fire the tags we want to measure.
Create a Facebook pixel tag (fires on all pages), Facebook page view tag (fires on the landing page url), Facebook click to purchase tag (fires when someone clicks to purchase)
Create a custom Google Analytics event that fires when someone clicks to purchase. This event will push to Google Analytics so we can see when the event triggers. We can also create audiences with this data.
Step 8: Test and confirm events
8.1 Test that the Facebook + Google Analytics tags are firing after clicking the add to cart button (Click to purchase).
8.2 Test to see if events are firing and send to Google Analytics after clicking the add to cart button (Click to purchase).
Want to take your Unbounce landing pages to the next level?
Check out the Ultimate List of Unbounce Tips, Scripts & Hacks