Skip to content
  • There are no suggestions because the search field is empty.

Install Google Tag Manager and track sign-ups and purchases

Add the Google Tag Manager container to Learnyst, push sign-up and purchase events, set up GA4 tags and triggers, then test in Preview before publishing.

Google Tag Manager (GTM) lets you manage GA4, Google Ads, Meta Pixel and other tags in one place, without editing your Learnyst site each time. You paste the GTM container code in Learnyst once, send sign-up and purchase events to GTM from Learnyst, and build the tags in GTM.

Before you start

Recommended setup

  1. Paste the GTM container code in Site Body Code and in the website builder's Header Code.
  2. Add the sign-up and purchase data layer code in Learnyst.
  3. In GTM, add the Google tag, then GA4 event tags with their triggers.
  4. Test everything in Preview, then Submit and publish a named version.
  5. Remove any old copies of the same tags from Code Snippets.

Step 1: Paste the container code in Learnyst

  1. In GTM, copy your container code. Google's current install guide uses one code block that goes as high in the <head> as possible (Google: 2. Install a web container). If GTM also shows a second <noscript> block for the <body>, Google describes that as the older snippet format; the code block for the <head> is the one you need.
  2. In Learnyst, go to Grow > Marketing > Integrations > Code Snippets.
  3. Click Site Body Code, paste the code at the end of the box, and click Save changes. Code saved here loads inside the <head> of your school site.
  4. If you use the website builder, go to Websites & Apps > Website > The all new Learnyst website builder > View Pages > More > Website Settings > Custom Code, paste the same code in Header Code, click Save, and publish your pages again.

The container code looks like this, with your own GTM- ID:

<!-- 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-XXXXXXX');</script>
<!-- End Google Tag Manager -->

Paste the container code once per page. Don't put it in both Site Footer Code and Site Body Code.

Step 2: Send sign-ups and purchases to GTM

Learnyst runs Signup Tracking Code when a learner signs up and Order Tracking Code on the thank-you page after a purchase. Use them to push an event into the data layer. GTM then fires your tags with a Custom Event trigger (Google: Custom event trigger).

Sign-up: in Grow > Marketing > Integrations > Code Snippets, click Signup Tracking Code and paste this in the second box, Place the function that should be called when learner signs up (Do not wrap script tag here):. Don't add <script> tags.

// dataLayer - sign-up (for Google Tag Manager). Box 2 of Signup Tracking Code (no <script> tags)
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
  event: 'sign_up',
  method: 'email',
  user_data: { email: String(email) } // Google Ads enhanced conversions only; never a GA4 parameter
});

The first Signup Tracking Code box, Place base conversion tag here :, runs on every page load, not only at sign-up. Put event code only in the second box, which runs once when a learner signs up successfully.

Purchase: click Order Tracking Code, paste this code and click Save changes. It passes the Learnyst variables receiptNumber, productPrice and courseTitle. Change INR if you sell in another currency.

<script>
  // dataLayer - purchase (for Google Tag Manager). Paste in: Order Tracking Code
  (function () {
    var price = parseFloat(String(productPrice).replace(/[^0-9.]/g, '')) || 0;
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({ ecommerce: null }); // clear earlier ecommerce data
    window.dataLayer.push({
      event: 'purchase',
      ecommerce: {
        transaction_id: String(receiptNumber),
        value: price,
        currency: 'INR',
        items: [{
          item_id: String(courseTitle),
          item_name: String(courseTitle),
          price: price,
          quantity: 1
        }]
      },
      payment_date: String(paymentDate),
      payment_time: String(paymentTime),
      // For Google Ads enhanced conversions only (GTM "User-Provided Data" variable).
      // Never send these to GA4 as event parameters.
      user_data: {
        email: String(email),
        phone_number: '+' + String(mobileNumber).replace(/[^0-9]/g, '') // Learnyst gives e.g. 919876543210
      }
    });
  })();
</script>

user_data holds the learner's email and mobile number for Google Ads enhanced conversions (map it with a User-Provided Data variable in GTM). Never send it to GA4 as an event parameter, because Google Analytics does not allow personal data.

Always use window.dataLayer = window.dataLayer || []; and push. Never write dataLayer = [...], which wipes the data GTM needs (Google: The data layer). Don't push email or mobileNumber if the data goes to GA4 (Google: Best practices to avoid sending Personally Identifiable Information (PII)).

Step 3: Add the Google tag for GA4

  1. In GTM, open Tags and click New.
  2. Click Tag Configuration. Under Google, click Google Analytics and choose Google Tag.
  3. Enter your GA4 Measurement ID (G-) in Tag ID.
  4. Under Triggering, choose Initialization - All Pages (Google: Set up Google Analytics in Tag Manager).
  5. Give the tag a clear name, for example GA4 - Google tag, and click Save.

GTM Choose tag type panel with Google Analytics, Google Ads, Floodlight and Other Google, and gallery templates such as Meta Pixel

GTM Google Tag with a Tag ID starting with G- and the Initialization - All Pages firing trigger

Step 4: Create the triggers

Create each trigger in Triggers > New. These are worked examples; change the values shown in italics to match your site.

Trigger Type Fires when Use it for
Purchase (recommended) Custom Event Event name equals purchase (pushed by Order Tracking Code) GA4 purchase, Google Ads conversion, Meta Purchase
Sign-up Custom Event Event name equals sign_up (pushed by Signup Tracking Code) GA4 sign_up, Meta CompleteRegistration
Checkout page view Page View (add a History Change trigger with the same condition to also catch in-app page changes) Page URL contains fast-checkout GA4 begin_checkout, Meta InitiateCheckout
Thank-you page view (alternative) Page View or History Change Page URL contains paymentStatusDisplay and Page URL contains status=true Only if you can't use the Custom Event. It carries no order value.

Before you use a URL-based trigger, open the page on your own site and check its address in the browser. Use the part that appears only on that page, and limit page triggers to the pages that need them (Google: Page view triggers).

Learnyst's checkout pages have addresses that contain fast-checkout, followed by an ID, and the Payment Successful page shown after a payment has an address like /learn/paymentStatusDisplay?…&receiptNumber=…&status=true. Some page changes on your learner site happen without a full page reload; a History Change trigger fires on these changes (Google: History change trigger). GA4 sends begin_checkout best with items, which the checkout page doesn't provide, so treat this event as a count of checkout visits (Google: Recommended events).

Why click triggers don't work on learner pages, and what to use instead

Your Learnyst learner pages (such as /learn, the store and course pages) are built from web components. When a learner clicks a button inside one of them, GTM's Click triggers (All Elements and Just Links, Google: Click trigger) only see the outer component, not the button itself. So a click trigger can't tell which button was clicked, and we don't recommend click triggers on learner pages.

Use these instead, from most to least precise:

  1. Signup Tracking Code and Order Tracking Code with a data layer push (Step 2). They run only after a real sign-up or purchase and carry the order details.
  2. Page address rules: a Page View or History Change trigger with Page URL contains a value, for example fast-checkout for checkout visits. Page changes inside the learner site still send a new page view with the new address, so address rules work on every learner page.
  3. Without GTM: in GA4, create an event from page_view with a matching condition such as page_location contains fast-checkout (Admin > Events > Create event, Google: Rename and generate new events).
  4. Developers only: a custom click listener in Site Body Code that reads event.composedPath() can see the real button inside a component and push your own data layer event. This needs a developer to build and maintain it, and it can stop working when Learnyst updates its page components.

Step 5: Add the GA4 event tags

  1. Create the variables the purchase tag needs: Variables > User-Defined Variables > New > Data Layer Variable, one each for ecommerce.transaction_id, ecommerce.value, ecommerce.currency and ecommerce.items.
  2. In Tags > New, choose Google Analytics > Google Analytics: GA4 Event. Enter your Measurement ID and the event name purchase, and add the parameters transaction_id, value, currency and items from the variables above (Google: Set up Google Analytics events in Tag Manager).
  3. Set the trigger to your Purchase Custom Event trigger and save.
  4. Repeat for sign_up with the Sign-up trigger (no parameters needed).

To send the same events to Google Ads or the Meta Pixel, add those tags with the same triggers. See Track Google Ads purchase conversions and Set up the Meta Pixel.

Step 6: Preview, then publish

  1. Click Preview. Enter the exact address of your Learnyst site, starting with https://, and click Connect. Use the domain where you pasted the container code: your school's learnyst.com address or your custom domain (Google: Preview and debug containers; Google: Troubleshoot with Tag Assistant).
  2. Browse your site in the window that opens. Check that the Google tag fires on every page.
  3. Sign up with a new test account, and buy a low-priced paid test product. Check that your sign-up and purchase tags fired, and that GA4 DebugView shows the events with their values (Google: Monitor events in DebugView).
  4. Back in GTM, click Submit. Give the version a clear name and description, for example "GA4 purchase and sign-up tags", and publish (Google: Publishing, versions, and approvals).
  5. If you added GA4, Google Ads or Meta in GTM, remove their old code from Learnyst Code Snippets and the builder's Custom Code, so each tool loads once.

If something breaks after publishing, open Versions and publish the previous version again. Named versions make this easy.

Best practices

Use cases

  • Agency running ads for a coaching institute: the agency gets GTM access and manages GA4, Google Ads and Meta tags without needing Learnyst admin access.
  • Several ad platforms: one purchase push from Order Tracking Code feeds GA4, Google Ads and the Meta Pixel through the same trigger.

Common mistakes

  • Double tagging: GA4 hard-coded in Code Snippets and also in GTM, or the container code pasted in two tabs (Google: [GA4] Troubleshoot tag setup on your website).
  • Click triggers on learner pages: they only see the outer web component, so use sign-up/order code or page address rules instead.
  • Event tags on All Pages: a purchase tag fires on every page view instead of only after a purchase (Google: Page view triggers).
  • Publishing without Preview, or with versions nobody can identify later.
  • Testing the wrong address in Preview or Tag Assistant, for example your root domain when the container is only on your school subdomain.
  • Forgetting to publish the container after testing. Changes in the workspace don't reach your site until you publish.
  • Overwriting the data layer with dataLayer = [...] (Google: The data layer).

If it doesn't work

  • Preview doesn't connect, or finds no tags: check that you entered the exact site address where the container is, that Save changes was clicked in Code Snippets, and that ad blockers are off. Check the container ID in your code matches the container you are previewing.
  • The container loads on some pages only: test a website builder page and a school page separately. Add the container code where it is missing, and publish builder pages again.
  • The purchase tag doesn't fire: make sure you bought a paid product (free courses don't create an order), the push is in Order Tracking Code inside <script> tags, and the trigger's event name matches purchase exactly. Event names are case-sensitive.
  • Values are empty: check the Data Layer Variable names, including the ecommerce. prefix.
  • Still stuck? Follow the tracking troubleshooting checklist.

What to do next

If you have questions, contact us at support@learnyst.com.