Google Tag Manager Code Integration for Default Flows – Google Analytics 4
Overview
The Google Tag Manager (GTM) is a small piece of JavaScript and non-JavaScript code (a container snippet) that you paste into your pages to configure or enable tags from Google Analytics or third parties. For more information on the Google Tag Manager and how to install it, click here: https://support.google.com/tagmanager/answer/6102821?hl=en&ref_topic=3441530
Setting the Google Tag Manager (GTM)
Add GTM code to your 2Checkout template
Log into your 2Checkout Merchant Control Panel.
Navigate to Setup → Interface templates.
Click Edit on the template that needs to be tracked.

In the Head Information area → Meta & CSS, paste the Google Tag Manager code for your account at the end of the existing code in that section. An example of the Google Tag Manager code is shown below:
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
<!-- End Google Tag Manager -->Example of the GTM snippet for the tag:
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXXXX"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->Place one snippet in the and the other in the of your website (if not already present). More info: https://developers.google.com/tag-manager/quickstart

Sending MyOrder Data to Google Analytics 4
By default, the myOrder object is available only for orders with payments authorized instantly (e.g., credit cards, PayPal) after successful authorization. To have the myOrder object available for all placed orders regardless of payment status (useful to send revenue for offline payment methods), enable the setting below.
Enable myOrder for all placed orders
Log in to your Control Panel: https://secure.2checkout.com/cpanel
Go to Setup → Ordering Options.
Scroll to the After sale message area and check Show message for all placed orders.

Click Save settings at the bottom of the page.
Make myOrder/analytics visible in Merchant Control Panel
Log in to your Control Panel: https://secure.2checkout.com/cpanel
Navigate to Setup → Ordering Options and click the Analytics tab.

Scroll to the Tracking script section (https://secure.2checkout.com/cpanel/web_analytics.php) and add a code snippet (for example add).
Apply the code to all languages or only to languages you want tracked.
Click Save at the bottom of the page.

A JavaScript object called myOrder is available on the Thank you page and provides information about purchased products (ID, quantity, name, price, etc.).
Google Tag Manager Configuration for Google Analytics 4
Create the Google Tag in Google Tag Manager
If you already have a Google Tag in your container that fires on all pages where GTM is added, you do not need to create a new Google Tag specifically for 2Checkout.
Create a Google Tag and add Measurement ID
In Google Tag Manager, select Google Tag from the list of predefined tags.
In the Tag ID section enter the Measurement ID from your Google Analytics 4 property: Admin → Data Streams → select your website property → copy Measurement ID.
Example where Measurement ID is located:

Send eCommerce information to Google Analytics 4 from the 2Checkout shopping cart
2Checkout shopping carts include a dataLayer with eCommerce information for Google Analytics 4. You can inspect it by typing dataLayer into the browser console and checking the gtag4 object for eCommerce info at checkout and on the order Finish page.

Configure Data Layer variables and create the GA4 event tag as follows.
Create Data Layer variables in GTM
Create the following User-Defined variables in Google Tag Manager (each variable is a Data Layer Variable, Data Layer Version = Version 2):
gtag4.event
gtag4.currency
gtag4.items
gtag4.tax
gtag4.transaction_id
gtag4.value
For each variable:
Variable Type: Data Layer Variable
Data Layer Variable Name: (use the exact name above)
Data Layer Version: Version 2
Example screenshots:

Create GA4 event tag to send eCommerce data
Create a new tag named: Google Analytics GA4 – 2 checkout event.
Tag Type: Google Analytics: GA4 event
Measurement ID: add the measurement ID for the GA4 property (usually same as the Google Tag). After adding it you'll see "Google Tag found in this container".
Event Name: use the previously configured variable gtag4.event (insert as {{gtag4.event}}).
Under Event Parameters, add these parameters and assign each the corresponding variable:
items → {{gtag4.items}}
currency → {{gtag4.currency}}
transaction_id → {{gtag4.transaction_id}}
value → {{gtag4.value}}
tax → {{gtag4.tax}}
Example properties screenshot:
Test your integration
Place an order in the 2Checkout shopping cart using the template that has your GTM code.
Log in to your Google Analytics 4 account.
Navigate to Monetization → Ecommerce purchases.

Review purchases and revenue for your products in GA4.

Last updated
Was this helpful?

