Automated Google Tag Manager (GTM) Container Generator for eCommerce Tracking (GA4 & Meta Pixel) and Custom Event & Lead Generation Tracking (Button Clicks, Scroll Depth, Timer, Lead Forms, Phone & Email clicks).
This project includes a 100% Client-Side Web Application (index.html) that requires zero backend servers or databases.
- Open directly in browser: Double-click
index.htmlto open in your browser offline. - Deploy to GitHub Pages:
- Push this repo to GitHub.
- Go to Settings > Pages > Branch:
main> Save. - Your tool will be live at
https://<your-username>.github.io/<repo-name>/!
- Deploy to Vercel:
- Import the GitHub repo;
vercel.jsonselects the Next.js framework preset, so the Studio, Validator, and DataLayer routes are built and hosted fromsrc/. - The standalone
index.htmlcopy is kept for offline use and GitHub Pages only (public/index.htmlis served as a static asset by Next).
- Import the GitHub repo;
- Variables (Strictly 24 User-Defined Variables):
- Constants (2):
Measurement Id,Facebook Pixel I'd - 1st Party Cookies (2):
FBC COOKIY(_fbc),FBP COOKIY(_fbp) - Data Layer Variables (16, Version 2):
DLV order_id,DLV value,DLV currency,DLV COPON Variable,DLV content_id,DLV-content_category,DLV_ content name,DLV EMAIL Variable,DLV PHONE Variable,DLV FIRST NAME Variable,DLV LAST NAME Variable,DLV CITY Variable,DLV POSTAL CODE Variable,DLV COUNTRY Variable,DLV items,DLV unique_event_id - Custom JavaScript Variables (4):
CJ_Event Id(deduplication),CJ_Event_Time,CJ quantity Variable,CJ contents
- Constants (2):
- Triggers (4 Custom Event Triggers):
View item Trigger(view_item)add_to_cart Trigger(add_to_cart)begin_checkout Trigger(begin_checkout)purchase Trigger(purchase)
- Tags (10 Production Tags):
- 5 GA4 Tags: Google Tag (Config),
GA4_view_item,GA4_AddToCart,GA4_begin_checkout,GA4_Purchase(with DataLayer pass-through & parameters). - 5 Meta Pixel Tags:
Fb Page view,Fb ViewContent,Fb AddToCart,Fb InitiateCheckout,Fb Purchase(with Event ID deduplication and Advanced Matching). - Embedded Official Meta Template: Bundles official Meta Pixel template (
templateId: "1") mapped tocvt_1_1.
- 5 GA4 Tags: Google Tag (Config),
- Server-Side Routing, Currency & Content Type (Optional):
server_container_urlconfiguration parameter on both the GA4 Configuration Tag andAW - Google Tag(enables server-side GTM routing).- Configurable
currency/x-fb-cd-currencyvalues for purchase and add_to_cart events (also exposed in the Studio UI). - Configurable
content_type(productorproduct_group) applied to GA4 event parameters and Meta object properties (also exposed in the Studio UI).
- Triggers (6 Interaction Triggers):
Scroll Depth - 25%, 50%, 100%: Vertical scroll percentage tracking.Timer - 10s, 30s, 60s Engagement: Active visitor engagement intervals.Click - Phone Number (tel): Detects and captures clicks on phone number links (tel:).Click - Email Link (mailto): Detects and captures clicks on email links (mailto:).Click - Button & Interactive Elements: All button and link click interactions (ID, Class, Text).Lead Form - Submission: Successful lead form submission capture.
- Tags (8 Interaction Tags):
- GA4 Tags (6):
GA4_click_button,GA4_scroll_depth,GA4_time_engagement,GA4_click_phone,GA4_click_email,GA4_generate_lead. - Meta Pixel Tags (2):
Fb Contact - Phone & Email Tag(Contactstandard event),Fb Lead - Form Submit Tag(Leadstandard event).
- GA4 Tags (6):
- Built-in Variables Auto-Enabled:
- Click ID, Click Classes, Click Text, Click URL, Click Element
- Scroll Depth Threshold, Scroll Depth Units, Scroll Direction
- Form ID, Form Classes, Form URL, Form Text
node src/index.js --ga4 G-XXXXXXXXXX --pixel 123456789012345 --preset all --out gtm_container.jsonnode src/index.js --ga4 G-XXXXXXXXXX --pixel 123456789012345 --server-url https://server.example.com --currency BDT --content-type product_group --out gtm_container.jsonnode src/index.js --ga4 G-XXXXXXXXXX --pixel 123456789012345 --preset ecom --out gtm_container.jsonnode src/index.js --ga4 G-XXXXXXXXXX --pixel 123456789012345 --preset leads --out gtm_container.jsonnpm.cmd test- Open Google Tag Manager.
- Select your Web Container and go to Admin.
- Under the Container column, click Import Container.
- Choose the generated
gtm_container.jsonfile. - Under Choose workspace, select Existing (e.g. Default Workspace).
- Under Choose an import option, select Merge → Overwrite conflicting tags, triggers, and variables.
- Click Confirm.
🎉 All variables, triggers, and tags are now instantly live in your workspace!