Quick answer
Your buyer pays on another website.
For example Gumroad, Stripe, Razorpay or Lemon Squeezy.
Your GA4 tag cannot run on that website.
So GA4 never sees the purchase.
The fix has three simple parts:
- Track the Buy click on your own site.
- Add the visitor’s GA4 ID to the Buy link.
- Send the sale back to GA4 with that ID.
This guide shows every click, with real screenshots.
We use Gumroad as the example.
Using another platform? Jump to this section.
We sell our ebooks on Gumroad.
Buyers click Buy on datametrik.com.
Then they pay on Gumroad, not on our site.
The money came in, but GA4 showed zero sales.
We fixed it with free tools only.
This post shows the exact setup we use today.
You do not need to know GA4 or GTM.
Just follow each step and copy each setting.
Not on Gumroad? This guide still works for you.
The idea is the same on every checkout platform.
We show the changes for other platforms near the end.
Simple words you need first
Read these once. They make the steps easy.
- GA4 is Google Analytics 4. It counts visits and sales.
- GTM is Google Tag Manager. It adds tracking code for you.
- Tag is a small piece of code that sends data.
- Trigger tells a tag when to run.
- Variable is a value a tag can read, like a price.
- Event is one action, like a click or a purchase.
- Client ID is GA4’s name tag for one visitor.
- Third-party checkout means payment happens on another website.
- Measurement Protocol lets a server send events to GA4.
- API secret is a password that allows those server events.
What you need before you start
- A GA4 property for your website.
- A GTM container installed on your website.
- An account on any checkout platform. We use Gumroad as the example.
- Stripe, Lemon Squeezy and many others also work.
- A free Google account for Google Apps Script.
- About 60 minutes of time.
New to GA4 tracking? Read our simple guide first.
It shows how to track form submissions in GA4.
How purchase tracking works on your own site
First, see the normal case.
Here, the whole sale happens on your website.

The buyer pays and lands on your thank-you page.
Your site then sends a purchase message to GTM.
This message is called a data layer push.
Your developer adds it to the thank-you page:
dataLayer.push({
event: 'purchase',
ecommerce: {
transaction_id: 'T-10234',
value: 1299,
currency: 'INR',
items: [{ item_name: 'CM360 Interview Q&A', price: 1299 }]
}
});In GTM, you create a Custom Event trigger.
Its event name is purchase.

Then you create a GA4 Event tag.
It sends the purchase to GA4 with four values.
These are transaction ID, value, currency and items.

That is all you need for on-site sales.
Every step happens where your tags can run.
Why it breaks on a third-party site
Now the hard part.
With Gumroad, the buyer clicks Buy and leaves.
The payment page is on gumroad.com.

Your GTM code is not on this page.
So your purchase tag never runs.
Gumroad has its own GA4 field.
But GA4 often sees that buyer as a new person.
So you cannot tell which page or visit sold.

Here is the fix in three parts.

- Track the Buy click on your site.
- Put the visitor’s GA4 ID on the Buy link.
- When Gumroad confirms the sale, send it to GA4.
Now let us set it up, step by step.
Step 1: Set up GA4
1.1 Open Admin
Open GA4 and select your property.
Click the gear icon at the bottom left.
This gear icon is called Admin.

1.2 Open your data stream
Under Data collection and modification, click Data streams.

Now click your website stream.

1.3 Copy your Measurement ID
Find Measurement ID at the top right.
It starts with G-.
Copy it into a notepad. You need it twice.

1.4 Add Gumroad to your domains
Scroll down on the same page.
Click Configure tag settings.

A new panel opens. Click Configure your domains.

Add two rows, both with match type Contains.
Row one is your website, like yoursite.com.
Row two is gumroad.com.
Then click Save at the top right.

1.5 Create an API secret
Go back to your web stream page.
Click Measurement Protocol API secrets.

Click Create.
Type a nickname, like gumroad.
Click Create again.

Copy the secret value into your notepad.
Keep it private, like a password.
That is why it is blurred here.

Step 2: Check the Google tag in GTM
2.1 Find the Google tag
Open Google Tag Manager.
Select your website container.
Click Tags in the left menu.
You need one Google tag with your Measurement ID.

Open it and check two things.
The Tag ID should be your Measurement ID.
The trigger should be Initialization – All Pages.
All Pages also works.

No Google tag yet? Click New, then Tag Configuration.
Choose Google Analytics, then Google tag.
Paste your Measurement ID and add the trigger.
Click Save.
2.2 Turn on built-in variables
Click Variables in the left menu.
Under Built-In Variables, click Configure.

Tick these click variables:
Click Element, Click Classes, Click URL, Click Text.

Also tick Page URL and Page Path.

Now GTM can read what was clicked.
It can also read which page is open.
Step 3: Create the variables
These variables give GA4 the product name and price.
3.1 Product name table
In Variables, under User-Defined Variables, click New.
Click Variable Configuration.
Choose RegEx Table.

Set Input Variable to {{Click URL}}.

Click Add Row once for each product.
Pattern: a unique part of the Gumroad link.
Output: the product name.
Tick Set Default Value and type unknown.
Name it RT – Product (click) and save.

3.2 Price table
Create a second RegEx Table the same way.
This time, the output is the price.
Set the default value to 0.
Name it RT – Price (click).

3.3 Page versions
Make the same two tables again.
This time, use {{Page Path}} as the input.
Name them RT – Product (page) and RT – Price (page).
Now each product page knows its own product.

3.4 Items variables
GA4 wants products in a list called items.
Two small code variables build that list.
Click New, then choose Custom JavaScript.

Paste this code. Name it CJS – Items (click).
function(){
return [{
item_id: {{Click URL}}.split('/l/')[1] ? {{Click URL}}.split('/l/')[1].split('?')[0] : 'gumroad',
item_name: {{RT – Product (click)}},
price: Number({{RT – Price (click)}}),
quantity: 1
}];
}
Make one more. Name it CJS – Items (page).
function(){
return [{
item_id: {{Page Path}},
item_name: {{RT – Product (page)}},
price: Number({{RT – Price (page)}}),
quantity: 1
}];
}Step 4: Create the triggers
4.1 Buy button click trigger
Click Triggers, then New.
Click Trigger Configuration and choose Just Links.

Untick Wait for Tags.
Untick Check Validation.
Gumroad’s pop-up stops the normal click.
With validation on, the trigger never fires.
Choose Some Link Clicks.
Set Click URL contains gumroad.com.
Name it Click – Gumroad links and save.

4.2 Product page trigger
Create a new trigger. Choose Page View.
Choose Some Page Views.
Set Page Path, matches RegEx.
Type a pattern that matches only product pages.
Our pattern is ^/ebooks-collection/[^/]+/?$.

4.3 Free sample click trigger (optional)
We also track clicks on free sample answers.
Choose All Elements, then Some Clicks.
Set Click Element, matches CSS selector.

We made one mistake here. Please avoid it.
We put two selectors in two separate rows.
GTM needs every row to be true.
No element matched both, so it never fired.
Put both selectors in one row, with a comma.

Step 5: Create the GA4 event tags
5.1 begin_checkout tag
Click Tags, then New, then Tag Configuration.
Choose Google Analytics.

Then choose Google Analytics: GA4 Event.

Paste your Measurement ID.

For Event Name, type begin_checkout.

Open Event Parameters. Click Add parameter four times.
currency= INR (or your currency)value={{RT – Price (click)}}items={{CJS – Items (click)}}product_name={{RT – Product (click)}}
Under Triggering, choose Click – Gumroad links.
Name it GA4 – begin_checkout and save.

5.2 view_item and view_sample tags
Repeat the same steps for view_item.
Use the product page trigger.
Use the (page) variables for value and items.
Optional: add view_sample on the sample trigger.

Step 6: Add the visitor ID to the Buy link
Do not skip this step.
Steps 6 and 7 work as a pair.
Without them, purchases never reach GA4.
6.1 Create a Custom HTML tag
Click Tags, then New, then Tag Configuration.
Choose Custom HTML.
Paste this code:
<script>
(function(){
var MID = 'XXXXXXXXXX'; // your Measurement ID without "G-"
function cookie(re){ var m = document.cookie.match(re); return m ? m[1] : ''; }
document.addEventListener('click', function(e){
var a = e.target.closest && e.target.closest('a[href*="gumroad.com"]');
if (!a) return;
try {
var u = new URL(a.href);
var cid = cookie(/(?:^|;\s*)_ga=GA\d\.\d\.(\d+\.\d+)/);
var sid = cookie(new RegExp('(?:^|;\\s*)_ga_' + MID + '=GS\\d\\.\\d\\.s?(\\d+)'));
if (cid) u.searchParams.set('ga_cid', cid);
if (sid) u.searchParams.set('ga_sid', sid);
a.href = u.toString();
} catch(err){}
}, true);
})();
</script>Change XXXXXXXXXX to your own Measurement ID.
Leave out the G- part.

6.2 What this code does
It reads the visitor’s GA4 client ID.
It also reads their GA4 session ID.
Both come from GA4’s own cookies.
When someone clicks a Gumroad link, it adds both.

6.3 Firing settings
Open Advanced Settings.
Set Tag firing options to Once per page.
Set the trigger to All Pages.
Name it and save.

6.4 Test it in Preview
Click Preview at the top of GTM.
Enter your website address and connect.
Open a product page.
Check that your passthrough tag fired.

Now click your Buy button.
The Gumroad address should show ga_cid and ga_sid.
No ga_cid? Step 7 will have nothing to match.
Fix this before you move on.
Step 7: Send every sale back to GA4
7.1 How it works
Gumroad has a feature called Ping.
After each sale, Ping sends the sale details.
It sends them to a web address you choose.
It also sends the ga_cid from the Buy link.
Many guides use Zapier for this part.
But Zapier webhooks need a paid plan.
So we use Google Apps Script. It is free.
7.2 Create the script
Go to script.google.com.
Click New project.

Rename the project, like Gumroad to GA4.
Delete the sample code.
Paste our script from the box below.
At the top, paste your Measurement ID.
Then paste your API secret from step 1.5.
Click the save icon.

Show the full Apps Script code
/**
* Gumroad Ping -> GA4 purchase (Measurement Protocol)
* Guide: https://datametrik.com/track-third-party-purchases-ga4/
*/
const MEASUREMENT_ID = 'G-XXXXXXXXXX'; // your GA4 Measurement ID
const API_SECRET = 'PASTE_API_SECRET'; // GA4 > Data streams > Measurement Protocol API secrets
const SELLER_ID = ''; // optional: your Gumroad seller_id
function doPost(e) {
const p = (e && e.parameter) ? e.parameter : {};
if (SELLER_ID && p.seller_id !== SELLER_ID) return reply_('ignored: wrong seller');
if (p.refunded === 'true' || p.disputed === 'true') return reply_('ignored: refund');
const cid = urlParam_(p, 'ga_cid');
const sid = urlParam_(p, 'ga_sid');
if (!cid) return reply_('ignored: no ga_cid');
const value = Math.round(Number(p.price || 0)) / 100; // Gumroad sends cents/paise
const currency = String(p.currency || 'inr').toUpperCase();
const params = {
transaction_id: p.sale_id || p.order_number || String(Date.now()),
value: value,
currency: currency,
engagement_time_msec: 1,
items: [{
item_id: p.product_permalink || p.permalink || p.product_id || 'gumroad',
item_name: p.product_name || 'Gumroad product',
price: value,
quantity: Number(p.quantity || 1)
}]
};
if (sid) params.session_id = sid;
const isTest = p.test === 'true';
const endpoint = 'https://www.google-analytics.com/' + (isTest ? 'debug/mp/collect' : 'mp/collect') +
'?measurement_id=' + MEASUREMENT_ID + '&api_secret=' + API_SECRET;
UrlFetchApp.fetch(endpoint, {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify({ client_id: cid, events: [{ name: 'purchase', params: params }] }),
muteHttpExceptions: true
});
return reply_('ok');
}
function urlParam_(p, key) {
if (p['url_params[' + key + ']']) return p['url_params[' + key + ']'];
if (p.url_params) {
try { const o = JSON.parse(p.url_params); if (o && o[key]) return o[key]; } catch (err) {}
const m = String(p.url_params).match(new RegExp('(?:^|[?&])' + key + '=([^&]+)'));
if (m) return decodeURIComponent(m[1]);
}
return '';
}
function doGet() { return reply_('Gumroad to GA4 endpoint is running'); }
function reply_(msg) { return ContentService.createTextOutput(msg); }
7.3 Deploy it as a web app
Click Deploy, then New deployment.

Click the gear icon next to Select type.
Choose Web app.

Set Execute as: Me.
Set Who has access: Anyone.
Click Deploy.

Click Authorize access and choose your Google account.
Google may say the app is not verified.
This is normal for your own script.
Click Advanced, then Go to your project.
Click Allow.
Now copy the Web app URL. It ends with /exec.
7.4 Connect Gumroad Ping
Open Gumroad. Go to Settings, then Advanced.
Paste the web app URL into Ping endpoint.
Click Update settings at the top right.
Then click Send test ping to URL.

7.5 Check the script ran
Go back to Apps Script.
Click Executions in the left menu.
You should see doPost with status Completed.

Test pings go to GA4’s test checker only.
They do not add fake sales to your reports.
The script also skips refunds.
It uses the Gumroad sale ID as the transaction ID.
So the same sale is not counted twice.
Step 8: Publish and test
8.1 Publish GTM
In GTM, click Submit at the top right.
Type a version name, like Third-party purchase tracking.
Click Publish.

8.2 Make a test purchase
In Gumroad, create a 99% off discount code.
Open your product page on your site.
Click your own Buy button.
Finish the checkout with the code.
8.3 Check GA4 Realtime
In GA4, open Reports, then Realtime overview.
Look for the purchase event.
It can take a minute or two.

8.4 Mark purchase as a key event
Go to Admin, then Events.
Click the star next to purchase.
Now GA4 treats it as a key event.

8.5 Stop double counting
Open Gumroad, Settings, Third-party analytics.
Keep the Google Analytics field empty.
Otherwise, GA4 may count each sale twice.

8.6 See your sales
Wait one or two days for full reports.
Open Reports, Monetization, Ecommerce purchases.
You will see views, checkouts and sales per product.

Not using Gumroad? Use any platform
Every checkout platform is a bit different.
But you only need to answer two questions.
Look in your platform’s settings or help pages.
Question 1: Can it send buyers back to your site?
Many platforms can open your own page after payment.
The setting is often called redirect URL.
It may also be called success URL or thank-you page.
If yes, use Method A below. It is the easiest.
Question 2: Does it send a sale alert?
A sale alert is called a webhook.
Gumroad calls it Ping. Others call it webhook or notification URL.
The alert must also return extra info from your Buy link.
If yes, use Method B. That is steps 6 and 7 above.
Method A: Thank-you page on your own site
The buyer pays on the other site.
Then the platform sends them back to your page.
Your GTM runs on that page, so GA4 sees the sale.
The same visitor comes back, so GA4 keeps their source.
You do not need step 6 or step 7 for this.
A1. Create a thank-you page
Make a simple page on your site, like /thank-you/.
Hide it from Google search with your SEO plugin.
A2. Set the redirect URL in your platform
Add the product, price and currency to the address.
Use one address for each product. Example:
https://yoursite.com/thank-you/?order_id={ORDER_ID}&product=My%20Ebook&value=499¤cy=INRChange {ORDER_ID} to your platform’s order ID code.
In Stripe Payment Links, it is {CHECKOUT_SESSION_ID}.
Search your platform’s help for “redirect URL placeholder”.
No order ID code? Leave that part out.
A3. Create four URL variables in GTM
Go to Variables, then New under User-Defined Variables.
Choose the variable type URL.
Set Component Type to Query.
Set Query Key to order_id.
Name it URL – order_id and save.
Repeat for product, value and currency.
A4. Create the items variable
Create a Custom JavaScript variable. Paste this code.
Name it CJS – Items (thank-you).
function(){
return [{
item_name: {{URL – product}},
price: Number({{URL – value}}),
quantity: 1
}];
}A5. Create the trigger
Create a Page View trigger. Choose Some Page Views.
Set Page Path contains /thank-you/.
Name it Page – Thank you and save.
A6. Create the purchase tag
Create a GA4 Event tag, like in step 5.
Set Event Name to purchase.
Add these four event parameters:
transaction_id={{URL – order_id}}value={{URL – value}}currency={{URL – currency}}items={{CJS – Items (thank-you)}}
Use the Page – Thank you trigger. Save it.
Then test and publish, like in step 8.
The order ID stops double counting if someone reloads the page.
One limit: a buyer may close the tab too early.
Then that one sale is missed. Method B catches it.
Method B: Sale alert (like our Gumroad setup)
Use this when the buyer never comes back to your site.
Follow steps 6 and 7 above, with two changes.
Change 1: In step 6, use your platform’s link field.
Gumroad keeps any extra link value, like ga_cid.
Other platforms use their own field name.
Change 2: In step 7, read the ID from that field.
The script must also read the price and order ID.
These field names differ by platform.
Here is a quick guide for popular platforms:
| Platform | Easiest method | What to look for |
|---|---|---|
| Gumroad | Method B | Ping in Settings, Advanced. Extra link values come back in url_params. |
| Stripe Payment Links | Method A | After payment, choose to redirect to your website. Use {CHECKOUT_SESSION_ID} as the order ID. |
| Lemon Squeezy | Method B | Add checkout[custom][ga_cid] to the link. It comes back in meta.custom_data of the order_created webhook. |
| Razorpay, Instamojo, course platforms and others | Method A if possible | Search their help for “redirect after payment” or “webhook”. |
Show the Lemon Squeezy changes for steps 6 and 7
Change gumroad.com to lemonsqueezy.com everywhere.
That means the step 6 code, the click trigger and step 1.4.
Change the line that adds ga_cid to this:
if (cid) u.searchParams.set('checkout[custom][ga_cid]', cid);
if (sid) u.searchParams.set('checkout[custom][ga_sid]', sid);In step 7, Lemon Squeezy sends data in a different format.
Replace the top part of doPost with this:
function doPost(e) {
const body = JSON.parse(e.postData.contents);
if (body.meta.event_name !== 'order_created') return reply_('ignored');
const custom = body.meta.custom_data || {};
const cid = custom.ga_cid;
const sid = custom.ga_sid;
if (!cid) return reply_('ignored: no ga_cid');
const a = body.data.attributes;
const value = Number(a.total) / 100; // total is in cents/paise
const currency = String(a.currency).toUpperCase();
const params = {
transaction_id: String(a.identifier || body.data.id),
value: value,
currency: currency,
engagement_time_msec: 1,
items: [{ item_name: a.first_order_item.product_name, price: value, quantity: 1 }]
};
if (sid) params.session_id = sid;
// keep the rest of the script from "const isTest" onwards
}In Lemon Squeezy, go to Settings, then Webhooks.
Paste your web app URL. Tick order_created. Save.
Make a test order. Check Apps Script Executions, like step 7.5.
No redirect and no sale alert?
Use the platform’s own GA4 setting, if it has one.
You will see the sales in GA4.
But you may not see which page or ad sold.
Common mistakes
- Check Validation is on. The click trigger never fires.
- Two CSS rows. Use one row with a comma.
- No
ga_cidon the link. Check step 6 first. - Wrong ID in the script. Use your own Measurement ID.
- Old Apps Script version. Deploy a new version after edits.
- GA4 ID inside Gumroad too. Sales get counted twice.
FAQs
Does this work for platforms other than Gumroad?
Yes. It works with most checkout platforms.
For example Stripe, Lemon Squeezy and many more.
If the platform can send buyers back to your site, use Method A.
If it sends a sale alert, use Method B.
See the any platform section for details.
Is this setup free?
Yes. GA4, GTM and Apps Script are free.
Gumroad Ping is also free.
Check if your platform charges for webhooks.
Why not just paste my GA4 ID in Gumroad?
GA4 often sees the buyer as a new visitor.
So you cannot see which page made the sale.
Will refunds show as sales?
No. The script ignores refunded and disputed sales.
How long until purchases show in reports?
Realtime shows them in a few minutes.
Standard reports can take one to two days.
Do I need a developer?
No. You only copy, paste and click.
A developer helps only for on-site data layer code.
Related guides
- How to track form submissions in GA4
- GA4 high-value audiences guide
- Floodlight conversion tracking in CM360
- Our ad tech ebooks (sold on Gumroad)
Want us to set this up for you?
We fix broken GA4 and GTM tracking every week.
See our GA4 setup service and GTM setup service.
Tracking can break silently. Drop Detective spots when conversions fall to zero while clicks stay normal, and alerts you the next morning: see how Drop Detective catches broken tracking →
Written By
Chetna leads content creation at Datametrik, turning complex programmatic workflows, ad operations, paid media strategies, and SEO frameworks into practical, step-by-step guides.
Technically Reviewed & Verified By
Every Datametrik guide is audited for live platform accuracy, bidding mechanics, and tracking setup by our technical editors with programmatic media buying and Ad Ops experience across WPP, Cognizant, and Dentsu.
Comments are closed.