Add tracking code to your Learnyst website
Where to paste GA4, Google Tag Manager, Google Ads and Meta Pixel code in Learnyst: Code Snippets tabs, variables and website builder Custom Code.
To measure visits, sign-ups and sales with Google Analytics, Google Tag Manager, Google Ads or the Meta Pixel, you add the tool's tracking code to your Learnyst website. Learnyst has two places for this: Code Snippets for your school site, and Custom Code in the website builder for pages you build there. This article explains which box to use for which code.
Before you start
- Custom code and Google Ads & Meta Ads tracking are included in every Learnyst plan. See learnyst.com/pricing.
- Copy the code from the tool you are adding (Google Analytics, Google Tag Manager, Google Ads or Meta Events Manager). Paste only code from tools you trust, because it runs on your site.
- Decide how you will install each tool: directly with its own code, or through Google Tag Manager. Use one way per tool, not both.
Recommended setup
- Paste each tool's base code (the code that loads on every page) once, in Site Body Code.
- Paste sign-up event code in Signup Tracking Code and purchase event code in Order Tracking Code.
- If you use the website builder, add the same base code once in Website Settings > Custom Code > Header Code, then publish your pages again.
- Test on your live site in a private browser window before you start ads.
The Code Snippets page
Go to Grow > Marketing > Integrations > Code Snippets. The page is called Code Snippets (Analytics Tracking Code & Custom Javascript Code) and has four tabs. Each tab has a Copy & paste your code here box and a Save changes button.

| Tab | What it is for | Paste here |
|---|---|---|
| Site Body Code | "Add analytics code, tracking pixels, or custom JS to your site." The code loads on the pages of your school site, inside the page <head>. |
Base codes: the GA4 Google tag, the Google Tag Manager container code, the Google Ads Google tag, the Meta Pixel base code, chat widgets. |
| Site Footer Code | The same description as Site Body Code. Code saved here also loads inside <head>. Only this tab has the Enable In Classroom checkbox. |
Use it as an alternative to Site Body Code, never in addition for the same tool. Verification meta tags work here too (see Verify your domain). |
| Signup Tracking Code | "Signup tracking code is triggered when a user successfully signs up to the site, independent of whether an order is placed or a course is enrolled in." It has two boxes: Place base conversion tag here : and Place the function that should be called when learner signs up (Do not wrap script tag here):. Available custom variable: email. |
The sign-up event, for example GA4 sign_up or Meta CompleteRegistration. Put it in the second box without <script> tags. |
| Order Tracking Code | "Order tracking code runs on the thank you page when a purchase is completed, and is typically used for purchase conversion tracking." JavaScript must be inside <script> tags. Free courses do not generate an order, so use Signup Tracking Code for free sites. |
The purchase event: GA4 purchase, the Google Ads conversion event snippet, Meta Purchase. |
Add code to Code Snippets
- Go to Grow > Marketing > Integrations > Code Snippets.
- Click the tab you need (see the table above).
- Click at the end of any code already in the box, add an empty line, and paste your code. Don't delete code that other tools need.
- Check that the code is complete, including its opening and closing
<script>tags (except in the second Signup Tracking Code box, which must not have them). - Click Save changes. To leave without saving, click Cancel.
As the page notes, please check if the scripts are working properly after you save them. See Check that it works below.
Variables you can use in sign-up and purchase code
The sign-up and purchase tabs list Available custom variables that you can put in your script, so each event carries the details of that sign-up or order. Type the names exactly as listed; they are case-sensitive.
| Tab | Variables | Typical use |
|---|---|---|
| Signup Tracking Code | email |
Only for tools that accept customer data, such as hashed matching in ad platforms. Never send it to Google Analytics. |
| Order Tracking Code | productPrice, paymentTime, receiptNumber, courseTitle, paymentDate, email, mobileNumber |
productPrice as the purchase value, receiptNumber as the unique order or transaction ID, courseTitle as the item name. |

Ready-to-copy event code is in Set up Google Analytics 4, Track Google Ads purchase conversions and Set up the Meta Pixel.
Add code to website builder pages
Pages you create with the Learnyst website builder have their own Custom Code settings, separate from Code Snippets. Add your base codes here too, at website level, so they load on every builder page.
- Go to Websites & Apps > Website > The all new Learnyst website builder. Your sites are listed under My Websites.
- On your website, click View Pages.
- Click More > Website Settings.
- Click Custom Code.
- Paste the base code in Header Code. As the page says, "This code will be embedded in the head of each page of the website."
- Click Save.
- Publish your pages again. The note on the page says: "Kindly publish all the pages of the website after integrating the custom code modifications." The More menu also has Publish Website.


Code for a single page only: on the page card, click the three-dot menu > Page Settings > Custom Code. Its Header Code "is not the same as header code in Website Settings, which will be executed on all pages of the website." Use it for page-only code, such as an event for one landing page. Click Save, then publish the page again.

Don't paste the same base code in both Website Settings and a page's Page Settings. That page would load it twice.
Ready-to-use code for each tool
Use only the blocks for the tools you have installed, and send each event in one way only. Learnyst fills in the variables (productPrice, receiptNumber, courseTitle, paymentDate, paymentTime, email, mobileNumber) when the code runs. Change INR if you sell in another currency.
Order Tracking Code (runs on the thank-you page after a purchase). Paste one or more of these blocks, one after another:
Meta Pixel:
<script>
// Meta Pixel - Purchase. Paste in: Order Tracking Code
// Replace YOUR_PIXEL_ID with your Pixel (dataset) ID.
(function () {
if (!window.fbq) return;
var price = parseFloat(String(productPrice).replace(/[^0-9.]/g, '')) || 0;
fbq('trackSingle', 'YOUR_PIXEL_ID', 'Purchase', {
value: price,
currency: 'INR', // change if you sell in another currency
content_name: String(courseTitle),
content_type: 'product',
num_items: 1,
order_id: String(receiptNumber)
}, {
eventID: String(receiptNumber) // same ID as your Conversions API event, so Meta counts it once
});
})();
</script>
Replace YOUR_PIXEL_ID with your Pixel ID (Events Manager > your dataset > Settings > Pixel ID). The code uses trackSingle so the event goes only to this pixel. A plain fbq('track', …) sends the event to every pixel installed on your site.
Google Tag Manager (data layer):
<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>
Google Analytics 4 without Tag Manager (gtag.js):
<script>
// Google Analytics 4 (gtag.js, no Tag Manager) - purchase. Paste in: Order Tracking Code
(function () {
if (!window.gtag) return;
var price = parseFloat(String(productPrice).replace(/[^0-9.]/g, '')) || 0;
gtag('event', 'purchase', {
transaction_id: String(receiptNumber),
value: price,
currency: 'INR',
items: [{
item_id: String(courseTitle),
item_name: String(courseTitle),
price: price,
quantity: 1
}]
});
})();
</script>
Signup Tracking Code, second box, Place the function that should be called when learner signs up (Do not wrap script tag here):. Paste the lines without <script> tags, one after another:
Meta Pixel:
// Meta Pixel - sign-up. Box 2 of Signup Tracking Code (no <script> tags)
if (window.fbq) { fbq('trackSingle', 'YOUR_PIXEL_ID', 'CompleteRegistration'); }
Google Tag Manager (data layer):
// 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
});
Google Analytics 4 (gtag.js):
// Google Analytics 4 (gtag.js) - sign-up. Box 2 of Signup Tracking Code (no <script> tags)
if (window.gtag) { gtag('event', 'sign_up', { method: 'email' }); }
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.
If you use Google Tag Manager, send GA4 events through GTM tags and skip the gtag.js blocks, so GA4 doesn't count each purchase twice. The user_data fields are for Google Ads enhanced conversions only; never send them to GA4 as event parameters.
One tag per tool
Each tool's base code must load once per page. Google's tag instructions say "Don't add more than one Google tag to each page" (Google: Add a Google Analytics property (to a site that already has Analytics)), and "You should only use either the Google tag or Tag Manager, not both" for the same Analytics property (Google: [GA4] Troubleshoot tag setup on your website). Meta also warns that duplicate base code produces duplicate events (Meta: Meta Ads Data Advisor).
- If you use Google Tag Manager, add GA4, Google Ads and the Meta Pixel inside GTM, and paste only the GTM container code in Learnyst.
- If you don't use GTM, paste each tool's own base code once.
- Several different tools are fine: paste one after another in the same box, with an empty line between them.
Check that it works
- Open your school website (not the admin panel) in a private browser window with ad blockers turned off. Use a page that doesn't need login, such as your home page or a course page.
- Check with the tool's own checker: Tag Assistant for Google tags and GTM (Google: Troubleshoot with Tag Assistant), Realtime in Google Analytics (Google: Realtime report), or Meta Ads Data Advisor and Test Events for the Meta Pixel (Meta: Meta Ads Data Advisor).
- For sign-up and purchase code, do a real test sign-up and a real paid test order. A page visit alone doesn't fire these events.
- Repeat the check on a website builder page, if you have one.
Use cases
- Coaching institute running Instagram ads: Meta Pixel base code in Site Body Code,
Purchasein Order Tracking Code, and the base code in the website builder's Header Code for the landing page the ads point to. - Exam-prep school measuring traffic sources: the GA4 Google tag in Site Body Code, with a
sign_upevent for free registrations. - Agency-managed tracking: only the GTM container code in Learnyst; the agency manages GA4, Google Ads and Meta tags inside GTM.
Common mistakes
- The same code in several boxes, for example the pixel in both Site Footer Code and Site Body Code, or GA4 pasted directly and again in GTM. Visits and purchases are then counted twice.
- Missing or broken
<script>tags, or only half of the code copied. Copy the whole snippet with the tool's copy button. <script>tags in the second Signup Tracking Code box, which says "Do not wrap script tag here".- Purchase code in Site Body Code instead of Order Tracking Code. It then fires on every page view, not on purchases.
- Forgetting website builder pages, or not publishing the pages again after changing their Custom Code.
- Testing on a page behind login, in the admin panel, or with an ad blocker on.
- Expecting a purchase event from a free course. Free courses don't create an order, so use Signup Tracking Code to count free registrations.
If it doesn't work
- The tag isn't found: check that you clicked Save changes, the code is complete, and you are testing your school site in a private window. Test a builder page and a school page separately: a tag found on one but not the other means it's missing from Code Snippets or from the builder's Header Code.
- The tag is found twice: search every tab of Code Snippets, the builder's Website Settings and Page Settings, and your GTM container for a second copy, and remove it.
- Old code still runs: remove it from every place listed above, click Save changes (or Save and publish again in the builder) and test in a new private window. If the tag is in GTM, also remove or pause it there and publish the container.
- Sign-up or purchase events don't arrive: check that the base code loads first, the event code is in the right tab, and you completed a real sign-up or paid order. Then follow the tracking troubleshooting checklist.
What to do next
- Set up Google Analytics 4 on your Learnyst website
- Install Google Tag Manager and track sign-ups and purchases
- Set up the Meta Pixel
- Tracking troubleshooting checklist
If you have questions, contact us at support@learnyst.com.