Free tool Data layer generator for GA4, GTM and TapCub
Choose one of Google’s 35 recommended events, fill in the parameters, and copy a ready dataLayer.push with the matching Google Tag Manager setup — or the gtag call, or the same event for the TapCub website script and SDKs. Required parameters, currency, item totals and GA4 naming limits are checked as you type.
- dataLayer · gtag · GTM
- Checks against Google’s rules
- Runs locally
Pick an event, get the code
Parameters are one per line as name=value; changing the event fills in the example values from Google’s reference. Put quotes around a value to keep it as text (an order number like "00123").
Letters, digits and underscores, starting with a letter.
One per line, name=value. Lines starting with # are ignored.
One item per line: item_id=…; item_name=…; price=…; quantity=…
Checks
- OKMatches Google’s reference for this event.
window.dataLayer = window.dataLayer || [];
dataLayer.push({ ecommerce: null }); // Clear the previous ecommerce object.
dataLayer.push({
event: "purchase",
ecommerce: {
currency: "USD",
value: 72.05,
customer_type: "new",
transaction_id: "T_12345",
coupon: "SUMMER_SALE",
shipping: 5.99,
tax: 3.6,
items: [
{
item_id: "SKU_12345",
item_name: "Stan and Friends Tee",
item_category: "Apparel",
price: 10.01,
quantity: 3
},
{
item_id: "SKU_12346",
item_name: "Google Grey Women's Tee",
item_category: "Apparel",
price: 21.01,
quantity: 2
}
]
}
});Put this where the action happens (after the order is confirmed, when the item is added…).
1. No variables needed: the tag reads the ecommerce object directly.
2. Triggers › New › Custom Event
Event name: purchase This trigger fires on: All Custom Events
3. Tags › New › Google Analytics: GA4 Event
Measurement ID: G-XXXXXXXXXX (the same ID as your Google tag)
Event Name: {{Event}} (or type purchase)
More Settings › Ecommerce › Send Ecommerce data, Data Source: Data Layer
Triggering: the "purchase" Custom Event trigger
4. Preview: open Tag Assistant, run the action, check the event in GA4 DebugView.One trigger and one tag per event. Ecommerce events read the ecommerce object, so no variables are needed.
Parameters in Google’s reference
| Parameter | Type | Required | Example in Google’s reference | Yours |
|---|---|---|---|---|
currency | string | Conditional | USD | set |
value | number | Conditional | 72.05 | set |
customer_type | string | No | new | set |
transaction_id | string | Yes | T_12345 | set |
coupon | string | No | SUMMER_SALE | set |
shipping | number | No | 5.99 | set |
tax | number | No | 3.6 | set |
items | array of items | Yes | — | set |
// Needs the Google tag (gtag.js) on the page already.
gtag('event', "purchase", {
currency: "USD",
value: 72.05,
customer_type: "new",
transaction_id: "T_12345",
coupon: "SUMMER_SALE",
shipping: 5.99,
tax: 3.6,
items: [
{
item_id: "SKU_12345",
item_name: "Stan and Friends Tee",
item_category: "Apparel",
price: 10.01,
quantity: 3
},
{
item_id: "SKU_12346",
item_name: "Google Grey Women's Tee",
item_category: "Apparel",
price: 21.01,
quantity: 2
}
]
});Use this instead of the dataLayer push if the site loads gtag.js directly.
Install and init are in the TapCub docs; only documented methods are used here.
Share these inputs: the values go after the # in the link, so they never reach a server.
https://tapcub.com/tools/data-layer-generator
Version v1.0Updated Update history
Which block to use
They describe the same event. Pick the one that matches how tags are installed on your site.
dataLayer.push + GTM
If the site uses Google Tag Manager. The page only pushes data; GTM decides which tags fire. Ecommerce events go inside an ecommerce object, cleared first with { ecommerce: null } so values from the previous event do not leak in.
gtag.js
If the Google tag is pasted straight into the page without GTM. Same event name and parameters, sent immediately.
TapCub SDK call
The same event for TapCub. The website, mini-program and app SDKs keep flat values only, so items are left out; the server SDKs keep one level of objects, so order lines and payments belong there.
Checks
Errors break reporting (a missing transaction_id, value without currency). Checks are worth a look (value not equal to the item total). Notes explain what happens, such as custom parameters needing a custom dimension.
“Yes” under Required means Google lists the parameter as required. “Conditional” is Google’s Yes*: currency is required once value is set, and value is needed for revenue reporting. “See note” is Google’s No*: items are optional, but without them refunds have no item-level refund metrics and select_promotion is left out of the Promotions report.
From event to working tag
Most of the work is choosing the event and making the values come from your page, not this example.
-
1
Pick the event
Use a recommended event when one fits — GA4 reports understand them. Otherwise choose “Custom event” and name it.
-
2
Fill in the parameters
Replace the example values with your own, or keep them while you test. Watch the checks.
-
3
Copy the code
Replace the literals with your variables (order number, total, cart lines) and run it where the action completes.
-
4
Set up and test
Follow the GTM steps, then check the event in Tag Assistant and GA4 DebugView — or in TapCub’s realtime view.
The rules the checks use
All GA4 rules are from Google’s own pages, checked on 2026-11-10: the recommended events reference, event naming rules and collection limits.
- value should equal the sum of price × quantity over the items, without shipping and tax; currency is a 3-letter ISO 4217 code and is required whenever value is set.
- Every item needs item_id or item_name; quantity defaults to 1.
- Event and parameter names are at most 40 characters and values at most 100, counted after URL encoding — non-Latin text uses the limit up faster. At most 25 parameters per event.
- For TapCub, event names registered in the catalog are lowercase snake_case up to 40 characters; the website script keeps 20 properties, mini-program and app SDKs 30.
| Limit | GA4 | TapCub |
|---|---|---|
| Event name | 40 characters, starts with a letter | 40 characters, lowercase snake_case |
| Parameters / properties per event | 25 | Web 20 · mini program / app 30 · server 50 stored |
| Text value | 100 characters | 200 (client SDKs) · 1,000 (server) |
| Arrays of objects | items, up to 27 custom item parameters | Server only (up to 100 elements) |
| Reserved prefixes | _ firebase_ ga_ google_ gtag. (parameters) | $ _ tc_ |
One purchase, three ways
The default example is Google’s own purchase sample: two items, 10.01 × 3 + 21.01 × 2 = 72.05.
| Block | Event name | Order number | Amount | Items |
|---|---|---|---|---|
| dataLayer / gtag | purchase | transaction_id | value 72.05 + currency | items array |
| TapCub website | purchase | order_id | revenue 72.05 + currency | left out (flat values only) |
| TapCub server (Node.js) | purchase | order_id and insertId | revenue 72.05 + currency | items array kept |
Renaming value → revenue and transaction_id → order_id is the “commerce report’s default names” option. Turn it off to keep GA4’s names; then set the mapping in TapCub’s business settings instead.
Why data layer events go missing
The code is short; the mistakes are in timing and values.
Not clearing ecommerce
Without dataLayer.push({ ecommerce: null }) first, items from a previous event can merge into the next one, because GTM keeps the data layer as one merged state.
Purchase fired on page reload
A thank-you page that pushes purchase on every load counts refreshes as orders. Fire once per order, and send the order from the server as well if revenue matters.
Numbers sent as text
“72.05” in quotes, or “1,299.00” with a comma, is a string. GA4 cannot sum it as revenue.
Custom parameters that never show up
A parameter that is not in Google’s list is collected but only appears in reports once you register it as a custom dimension or metric.
Events without a tag manager
TapCub collects pageviews and clicks with one script; named events are one call, on any platform.
One script, then one call
client.js records pageviews, sources, outbound clicks and downloads on its own. A custom event is tapcub.track(name, props).
Learn moreSDKs for apps and mini programs
The same event names on iOS, Android, Flutter, React Native, uni-app and WeChat / Alipay / Douyin mini programs.
Learn moreServer events for money
Payments and refunds from your backend with an idempotency key, so retries never double revenue.
Learn moreData layer questions
Still have a question?
Chat with the team behind TapCub — we usually reply within a few hours on business days.
What is a data layer?
A JavaScript array, window.dataLayer, that the page pushes events and values into. Google Tag Manager reads it and decides which tags to fire, so the page does not need to know about each tool.
How do I push an event to the data layer?
Call dataLayer.push({ event: "sign_up", method: "Google" }). In GTM, a Custom Event trigger with the same event name fires the tag, and Data Layer Variables read the other keys. This tool writes both the push and the setup steps.
Why push { ecommerce: null } first?
GTM merges every push into one data layer state. Clearing the ecommerce object first stops items from the previous event ending up in the next one. It is the pattern in Google’s ecommerce guide.
What is the difference between dataLayer.push and gtag?
gtag sends the event straight to Google Analytics. dataLayer.push only records it in the page; GTM then sends it to GA4 and any other tag. gtag itself works by pushing into the same dataLayer array.
Which GA4 parameters are required?
It depends on the event: purchase needs transaction_id and items; search needs search_term. currency is required whenever value is set. The parameter table under the code shows the list for the event you pick.
Can I send the same event to GA4 and TapCub?
Yes. Keep the same event name. TapCub’s website script takes flat values, so send line items from the server; the commerce report reads revenue, currency and order_id by default, which the rename option fills in.
Does the TapCub code send personal data?
Only what you put in. The server examples have a USER_ID placeholder for your own ID; email and phone identifiers are hashed by the SDKs, but do not put them in event properties.
Is anything uploaded?
No. The code is generated in your browser; nothing you type is sent anywhere.
Update history
New features, fixes and data refreshes for this tool, newest first.
-
· v1.0
LaunchedFirst release.
Data this tool relies on
- GA4 recommended events — checked 2026-11-10, reviewed every 6 months (next review by 2027-05-10)
Missing something or found an error? Tell us — requests that come up often go into the next update. All tool updates
Plan first, then code
Write down which events and properties you need, then generate the code for each.