Tracking shop.app button clicks with Google Tag Manager

Tracking shop.app button clicks with Google Tag Manager

Shopify site owners will no doubt be using, or at least be familiar with their ‘one-click checkout’ functionality.

It comes with a few benefits, such as:

  • Reduced friction to finalise purchase
  • Checkout process is super quick
  • Customer details typically stored and requested all at once for speed

While this is all great, it does present itself a challenge to site owners from a data tracking perspective. The one-page checkout, identifiable as shop.app, is its own domain. Using Google Tag Manager (GTM) and Google Analytics 4 (GA4), we can get this tracking correctly.

Shop.app example with the anchor text Buy It Now

What do we need to get started?

To get started, you’ll need to be setup with the following tools:

  • Google Tag Manager
  • Google Analytics 4
  • (optional) Chrome DevTools with dataLayer tracking such as DataSlayer

Step 1: Set up a user-defined variable in GTM

What is a variable in GTM?
A variable is a symbol that represents a value that can change

How are variables applied to triggers and tags?
In triggers, variables define filters that specify when a tag should fire. It is essentially whether the user meets the conditions of the trigger or not.

In tags, variables capture dynamic values. The code from the tag is sent through to GA4.

Let’s get right onto setting up a user-defined variable.

  1. Open Google Tag Manager
  2. Click Variable in the left sidebar
  3. In the User-Defined Variables section, click add New
GTM - where to add new variable
  1. Fill in the following information:
    • Variable Type (Choose your variable type selector) = Auto-Event Variable
    • Variable Type = Element URL
    • Component Type = Is Outbound
    • Affiliated Domains = Shop.app
  2. Hit Save
GTM - auto-event variable example

📖 Glossary of the above:

  • Auto-Event Variable: this is a user-defined variable type that stores information when auto-event actions are executed, such as a click, form submission, element visibility, or error.
  • Element URL: This accesses the gtm.elementUrl in the dataLayer and returns the value of either the href or the action attribute of the event element.
  • Is Outbound: Determines whether the links is internal or outbound. If the link is not your domain or an affiliated domain, it will return the value ‘true’. If the click is your domain or affiliated domain, it will return a ‘false’ value.
  • Affiliated Domains = Shop.app: The domains that you input in this section will be treated as internal domains.

Step 2: Setup your tag

Tags are the information that is sent from GTM to GA4 when our trigger conditions are met.

Here is what we’ll need to setup:

  1. Click Tags in the left sidebar
  2. Click New on the top-right
  3. You should now see the Tag Configuration window. Click Tag Type and select Google Analytics: GA4 Event
  4. Input your Measurement ID from GA4. You can find this by opening GA4 and navigating to Admin > Data Streams and then copy & pasting your Stream ID.
  5. Name your event. In this example I matched the anchor text of the button, “buy_it_now”
  6. Set your event parameters and values. I’ve used the following:
Event ParameterValue
buy_it_now{{Buy It Now – Outbound Click}}
click_url{{Click URL}}
click_text{{Click Text}}
click_element{{Click Element}}
  1. Save your tag
GTM - Tag configuration for shop app

Step 3: Setup your trigger

Directly after creating your tag, you’ll see the option to directly create a trigger. Click on that, and we’ll get started.

  1. Trigger Type: Click All Elements
  2. This trigger fires on: Some clicks
  3. This step is dependant on the anchor text of your shop.app link, so replace what I’ve shared below with your own:
    {{Click Text}} contains BUY IT NOW
GTM - Trigger configuration for shop app

Step 4: Open your website in Preview mode

Now that you’ve setup your tag and trigger, it is crucial to preview your changes before deploying.

Next to the Submit button on the top-right is the Preview button. Click it and then paste in your website URL. It will look like below:

GTM - Preview Mode Step 1
GTM - Preview Mode Step 2
Screenshot

Step 5: Test and debug your tracking with Tag Assistant

When preview mode is activated, it will open a new tab of your website and it will track all actions, loaded elements, triggers and tags. This is called Tag Assistant.

You will want to navigate to a page that has the one-page checkout button. Once there, click on the button and then go back to the Tag Assistant window.

If successful, you should see results like below:

GTM - Buy it now button firing in tag assistant
GTM - Example of the parameters of the Buy it now button

If unsuccessful, you’ll need to go through some debugging to see if any of the tag event parameters are not being met.

Step 6: Setup a Custom Event in GA4

We need the data that is sent from GTM to GA4 to be correctly labelled.

  1. In the bottom-left corner, click Admin
  2. Click Events
  3. Click Create Event
  4. Give your event a name
  5. Set your Matching Conditions:
ParameterOperatorValue
event_nameEqualsbuy_it_now
GA4 - Custom event for Buy It Now

Step 7: Setup a Custom Metric in GA4

Finally, we want this event to be an available metric in GA4 when we do our own Explorations.

  1. In the bottom-left corner, click Admin
  2. Click Events
  3. Click Custom Definitions
  4. Click Custom Metrics
  5. Click Create Custom Metric
  6. Fill in the details and make sure you assign your ‘buy’ Event Parameter.
Custom metric example

Conclusion

I worked through this solution when I saw a big discrepancy between ‘add to carts’ and ‘purchases’ when reviewing my funnel metrics. The number of ‘purchases’ was higher than ‘add to carts’, and I thought that was super weird. I’ve only recently tested this tracking setup, so I do hope it’s the silver bullet to this tracking trouble.

This data is also great for funnel explorations. Below is an example of how this could look in GA4’s Explorations.

GA4 Exploration - Buy it now funnel

Leave a Reply

Your email address will not be published. Required fields are marked *