Lemon Squeezy · Google Analytics, Google Ads, Meta Pixel & More

Intro

🍋 This blog post isn't much of a blog post at the moment. I’ll be updating more info soon – promise.

For now post is just a short snippet where I’ll embed a Lemon Squeezy conversion tracking video I just recorded. I just switched to Lemon Squeezy (loving it by the way!) and needed to figure out conversions for it.

Video

Lemon Squeezy Google Tag Manager Setup

The video above shows you a method I used to track my Lemon Squeezy conversions, and send the conversions to Google Analytics, Google Ads and Facebook Pixel.

We are using Google Tag Manager, a custom JavaScript listener and also doing enhanced conversion tracking for Google Ads using user-provided data, in this case, the lemon squeezy email the client gave us. Take a look, and hit me up if you want Lemon Squeezy conversions tracked like in the video 👇

The Method

Lemon Squeezy iFrame JavaScript Listener

It’s impossible to know what happens inside an iFrame as it’s essentially another website and we don’t have access to lemonsqueezy.com.

However, nice iFrames (like Lemon Squeezy) are kind enough to share a JavaScript message with the parent window (our website) that we can listen for, and use to trigger our conversions.

iFrame Event

The event we get from Lemon Squeezy is

"event": "Checkout.Success",

Data

We also get a bunch of useful data about the Lemon Squeezy purchase, such as

  • variant_name

  • product_name

  • subtotal_formatted

  • tax_usd

  • subtotal_usd

  • total

  • currency

  • user_email

  • user_name

  • order_number

  • identifier

We will use the message JavaScript message listener

addEventListener("message", (event) => {});

Data Layer and Custom Google Tag Manager Event

Using a Custom HTML Tag in Google Tag Manager, we will fill our Google Tag Manager Data Layer using the GA4 ‘purchase’ event format

dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
dataLayer.push({
  event: "purchase",
  ecommerce: {
    transaction_id: "T_12345",
    // Sum of (price * quantity) for all items.
    value: 72.05,
    tax: 3.60,
    shipping: 5.99,
    currency: "USD",
    coupon: "SUMMER_SALE",
    items: [
    {
      item_id: "SKU_12345",
      item_name: "Stan and Friends Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 2.22,
      index: 0,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "green",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 10.01,
      quantity: 3
    },
    {
      item_id: "SKU_12346",
      item_name: "Google Grey Women's Tee",
      affiliation: "Google Merchandise Store",
      coupon: "SUMMER_FUN",
      discount: 3.33,
      index: 1,
      item_brand: "Google",
      item_category: "Apparel",
      item_category2: "Adult",
      item_category3: "Shirts",
      item_category4: "Crew",
      item_category5: "Short sleeve",
      item_list_id: "related_products",
      item_list_name: "Related Products",
      item_variant: "gray",
      location_id: "ChIJIQBpAG2ahYAR_6128GcTUEo",
      price: 21.01,
      promotion_id: "P_12345",
      promotion_name: "Summer Sale",
      quantity: 2
    }]
  }
});



Creating a Custom Google Tag Manager Event Trigger

Next up, we will create a trigger for our conversion tags. For this we use the Google Tag Manager custom event, and use the same event name as in our data layer push.

Google Analytics 4

Nothing is sure except death and taxes

One thing to note is that we get Lemon Squeezy prices both including taxes and without. I prefer to use the ‘subtotal’ without taxes for Google Ads conversion, Facebook Pixel conversion etc. but use the ‘total’ for Google Analytics 4 event, containing taxes because Google Analytics has the tax field we can use. I trust Google Analytics to handle it correctly. I double-checked Simo Ahava’s reference for the GA4 purchase, to make sure the value should contain taxes (and theoretically shipping costs but we don’t really worry about those if we use Lemon Squeezy).

Google Tag Manager Tag

The Google Analytics event is a built-in tag within Google Tag Manager. Make sure to check “data layer” as the source of our data.

We use a ‘purchase’ event, which is a conversion event by default. GA4 event is lowercase, Facebook Pixel event uppercase ‘Purchase’

Google Ads

I use the standard Google Tag Manager tag for Google Ads conversion. We should also remember to fire the Conversion Linker tag in Initialization.

Enhanced Conversions - Making Google Ads conversions more accurate

For Google Ads, I recommend also creating a user-provided data variable in Google Tag Manager, and populating the Lemon Squeezy email. Enhanced conversion tracking makes conversion tracking more accurate. You can check out my blog post about what exactly are enhanced conversions in Google Ads, here

Facebook Pixel

Although there are built-in setups in the Google Tag Manager template gallery, I prefer to make an old-school Custom HTML <script> tag for the Facebook Pixel Lemon Squeezy event. I’ve just found these more reliable. We use a ‘Purchase’ event, which is a conversion event by default.

Testing

Google Tag Assistant

I recommend getting the Google Tag Assistant Companion from Chrome web store

Note, always use test mode for your test purchases. As per Lemon Squeezy emails (screenshot below)

lemon Squeezy conversion tracking advice via email - always use test instead of a real card

Testing Card

You can use 4242 4242 4242 4242 for the card number and andy CCV and expiry date.

Previous
Previous

Jotform Conversion Tracking – 7 methods ranked best to worst

Next
Next

”Code + Tonic” is now conversiontracking.io