Enhanced Ecommerce Tracking With Google Tag Manager in aMember

If you are using Google Tag Manager (GTM) to handle your Google Analytics, then you will need a way to populate the dataLayer with eCommerce data when you make a sale in your aMember site.

Here’s how I do it on my sites, using aMember’s own Conversion Track plugin.

Step 1: Add the dataLayer in Conversion Track plugin settings

NB: If you don’t have Conversion Track, you can order it from the “Addons Shop” in your aMember account.

I use two versions of the code so that initial payments are tracked separately to rebills. Here are the two code snippets in full:

Sale Tracking Code (For rebills)

<script>
// Sends transaction data with a pageview (DOM Ready)
dataLayer.push({
  'event': 'amPurchase',
  'ecommerce': {
    'currencyCode': '%payment.currency%',
    'purchase': {
      'actionField': {
        'id': '%payment.transaction_id%', // Transaction ID. Required for purchases and refunds.
        'affiliation': '%afflogin%',
        'revenue': '%payment.amount%',    // Total transaction value (incl. tax and shipping)
        'tax':'%payment.tax%',
        'shipping': '%payment.shipping%',
        'coupon': '%invoice.coupon_code%'
      },
      'products': [
           // List of productFieldObjects.
           %foreach_product%{
           'name': '%item.item_title%',       // Name or ID is required.
           'id': '%item.item_id%',
           'category': 'Rebill', 
           'price': '%item.second_total%',
           'quantity': '%item.qty%',
           'coupon': '%invoice.coupon_code%'  // Optional fields may be omitted or set to empty string.
           },%endforeach_product%
       ]
    }
  }
});
</script>

First Sale Tracking Code

<script>
// Sends transaction data with a pageview (DOM Ready)
dataLayer.push({
  'event': 'amPurchase',
  'ecommerce': {
    'currencyCode': '%payment.currency%',
    'purchase': {
      'actionField': {
        'id': '%payment.transaction_id%', // Transaction ID. Required for purchases and refunds.
        'affiliation': '%afflogin%',
        'revenue': '%payment.amount%',    // Total transaction value (incl. tax and shipping)
        'tax':'%payment.tax%',
        'shipping': '%payment.shipping%',
        'coupon': '%invoice.coupon_code%'
      },
      'products': [
           // List of productFieldObjects.
           %foreach_product%{
           'name': '%item.item_title%',       // Name or ID is required.
           'id': '%item.item_id%',
           'category': 'Initial Sale', 
           'price': '%item.first_total%',
           'quantity': '%item.qty%',
           'coupon': '%invoice.coupon_code%'  // Optional fields may be omitted or set to empty string.
           },%endforeach_product%
       ]
    }
  }
});
</script>

If you look carefully, the snippets only vary in the product category (“Rebill” vs “Initial Sale”) and product price, as aMember can charge a separate amount initially (e.g. $1 trial).

Step 2: Setup the Event Trigger in GTM

You may have noticed that my dataLayer snippets use an event to ensure the data is sent to GTM, so you will need to implement a custom event trigger called amPurchase in your GTM so that it knows what to do when aMember updates the dataLayer with your conversion data.

Here’s what mine looks like:

Step 3: Attach a UA Transaction Tag To The Trigger

Again, here’s what mine looks like:

And that’s it!

Please share your thoughts

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

Want a pic to show with your comment?
Go get a Gravatar