How To Track a shared Payment Gateway with GTM
How To Track a shared Payment Gateway with GTM

Many websites use a shared payment gateway because it’s the most sensitive and secure part of the user journey. That’s why it can be a challenge to get approval to get Google Tag Manager (GTM) integrated into the payment gateway. It’s not unusual for Information Security to cite PCI compliance as a reason to prevent such integrations. However, I will discuss this later.
There are normally two options available for implementing a payment gateway. An iFrame embedded into an order page or a redirect to another domain (where the browser will show a different URL). If your organisation owns these domains this makes life a lot simpler. If you are using a commercial payment gateway provider you will have to accept less control in your tracking. In this post I will focus on the scenario where your organisation owns the shared payment gateway.
Commercial Payment Gateway:
If you use a commercial shared payment gateway, such as a bank or Paypal, your options are more limited. These organisations won’t normally give you direct access to their domain because they may be servicing literally thousands of websites. You will certainly need to configure Google Analytics to ensure you are tracking true referrals.
However, they often will enable integration with your analytics though by passing data to your payment confirmation page. They may also provide separate reporting on payment error messages and card declines. This is a discussion you should have with your payment gateway supplier.
Your Shared Payment Gateway:
However, if your organisation owns your shared payment gateway you should have the opportunity to implement Google Analytics via GTM to provide your own reporting. PCI compliance should not be a barrier to integrating GTM in your payment gateway because;
- GTM script does not need to be PCI compliant because it is not designed to or is capable of processing payment card information.
- GTM is managed internally by most ecommerce sites. This means it is easy to set up controls and processes to ensure proper testing in DEV or UAT are undertaken before publishing changes to the live environment.
- Google Analytics is GDPR compliant and you are not allowed to collect personally identifiable information. This should be monitored by your organisation’s Data Protection Officer and by the protocols established by the analytics team.
Integrating Google Analytics via GTM into your shared payment gateway will allow you to measure user interactions in probably the most important step in the customer journey. For example, it will allow you to track payment error messages, payment failures and enrich GA with transactional data.
1. Implement Enhanced Ecommerce:
Before adding GTM to your payment gateway it’s a good idea to implement enhanced ecommerce tracking on your thank you or order confirmation pages. This will allow you to send transactional and other purchase related data directly to Google Analytics. This may save you having to implement cross-domain tracking and allows you to separately integrate your payment gateway.
Depending upon what you plan to measure in your payment gateway, you may also decide to implement enhanced ecommerce tracking within your payment gateway. This could be useful if you want to match up behavioural and transactional data within a shared gateway.
If your site has exclusive use of your payment gateway then you can implement cross-domain tracking to integrate with your primary domain. In this instance you can follow the instructions in my blog a guide to cross-domain tracking.
If you share your payment gateway across multiple brands this becomes more complex. For example, you don’t want to have to implement a separate script for each brand you wish to track as this can slow your payment gateway down and scripts can sometimes conflict. You may also want to capture behavioural and transactional data across all brands.
2. Set up a new Google Analytics Account:
Go to Google Analytics and create a new property in your organisation’s GA account. So that you can test in different environments I always set up separate properties for production, DEV, SIT and UAT. Copy and paste each property ID into your GTM Tag Plan as you will need them for later.
Go to the ‘View Settings’ and change the ‘View Name’ to reflect the environment and data it collects as this helps when selecting the data source in Google Data Studio.
3. Implement GTM Script:
Go to your organisation’s GTM account and create a new container for the ‘Payment Gateway’. This will take you to the page with the GTM script needed for implementation. Copy the instructions and script into a Word document so that you share with the developer who will add the script to the payment gateway.
4. Configure your GTM container:
To minimise the effort in setting up variables, triggers and tags you can copy a suitable container that you have already configured. Go to a container that is as close to what you need as possible and then go to; Admin > ‘Export Container’ > ‘Choose a version or workspace’ – usually the latest version you have – and click on ‘Export’.
Then go back to the container for the payment gateway and select the ‘Admin’ tab. Now select; Import Container > Choose Container file (select the container file you just exported to your hard drive) > Overwrite (unless you have already configured some tags) and the ‘Confirm’.
You will now need to go to the GA Tracking ID variable or create one if your container doesn’t already have one. To create one go to Workspace > Variables > User-Defined Variables – New and complete as follows;
Call the variable ‘GA Tracking ID’
Variable Type: Lookup Table
Input Variable: Page Hostname
Input: Enter the URL (without www. and no trailing slashes at the end) for the first property (e.g. for Production)
Output: Copy and paste the GA Property ID for that environment
‘+Add Row’ for each individual environment and the GA Property ID until you have included them all. I don’t use the ‘Set Default Value’ as it’s not necessary here.
Now to go to your ‘GA Settings’ variable and replace the GA Property ID with your new ‘GA Tracking ID’ variable. This will ensure data is automatically directed to the correct property for each environment.
5. Create views for each brand/site:
Make sure you set up a raw Data view with no filters, a reporting view with all your required filters, and then replicate this for your test view. It’s also useful to have a view dedicated to each brand/site. You could use custom segments, but you can only apply a maximum of four segments at a time and for ease of use it is good to have a view with a single brand/site so that you don’t have to keep setting the correct segments.
Use a filter of the referrer URL to strip out all users apart from the brand you are wishing to monitor here. To implement this go to the ‘Admin’ section and under ‘View’; +ADD FILTER > Create new Filter > Filter Name (Referral – Brand XXXX’ and select the following:
Filter Type: Custom
Filter Field: Referral
Select: Include
Filter Pattern: Input the site’s URL without the www. and use the Regex character ‘\’ before any dots or ‘-‘ to indicate that it should be interpreted literally and not as the Regex metacharacter.
If you already have data then you can ‘Verify this filter’ to check it is working and then ‘Save’. Repeat this process for all the brands/sites that use the shared payment gateway.
6. Prepend Hostname:
As you are likely to want to include payment gateway data in your Google Data Studio reports it is a good idea to prepend the hostname to the page path to provide clarity of the pages users navigate to.
To do this go to the ‘Admin’ section of your Google Analytics Property and Filters > ADD FILTER > Create new Filter. Now follow these instructions;
Filter Type: Advanced
Field A -> Extract A:
Hostname: (.*)
Field B -> Extract B:
Request URL: (.*)
Output To -> Constructor
Request URL: $A1$B1
Field A Required – Tick
Override Output Field – Tick
Then save the filter and check the view later to see if the domain has been appended to the page path.
7. Test, Test, Test:
At each step of the process it’s important to test that everything is working as you expect. Use a combination of tools to check the data quality, from Google’s Dev tools, GTM preview mode, Google Analytics Debugger and the Google Analytics Realtime tab. It’s important that your business has full confidence in your data and so allow plenty of time for testing. This is not something you should rush if it all possible.
8. Create Visibility Tags for Error Messages:
To set up visibility tags for error messages displayed to users you first need to check that developers have included IDs or unique CSS selectors for each message. If the messages don’t have them ask a developer to add them to all payment error messages. Ask them to use a suitable prefix (e.g. ERR_) and to confirm the wording and purpose of each message. You will then be in a position to create visibility triggers using either the ID or CSS selector. Use these triggers to set up a Tag for error messages.
9. Create Automated Reports in Data Studio:
Now that you have your data in Google Analytics you have the opportunity to create automated dashboards in Google Data Studio. I often use Data Studio to create complex funnel visualisations for conversion tracking. Now that you have payment gateway data you can add more granular information to conversion rate reports around payment errors and field interactions. This can be invaluable in optimising your conversion journey.
Summary:
Shared payment gateways offer a number of challenges to the data analyst but also represent a major opportunity to provide more granular data on the most important step in the user journey. Don’t let PCI compliance get in the way of implementing GTM as this is an excuse that does not stand up to scrutiny.
Implementing enhanced ecommerce tracking on your thank you pages will help enrich the data you collect for individual brands. Integrating GTM into your payment gateway though will give you real insights into user behaviour and the performance of your transactional platform which is crucial to the survival of your business.
Comments