All Posts
2026-04-10|NXFLO

GTM Programmatic Tag Management: Creating 28 Tags via API

How NXFLO uses the Google Tag Manager API to create tags, triggers, and variables programmatically — without ever opening the GTM interface.

gtmtrackingapiautomation

GTM Programmatic Tag Management: Creating 28 Tags via API

Google Tag Manager is powerful but manual. Every tag requires clicking through a UI, selecting types, configuring parameters, mapping triggers, and publishing. For an enterprise setup with 28 tags, 22 triggers, and 36 variables — that's hours of repetitive work.

We built NXFLO's GTM integration to do all of it via API. Here's what we shipped.

The Tool Set

11 tools for full container control:

Tool What it does
gtm_list_tags List all tags in the container
gtm_list_triggers List all triggers
gtm_list_variables List all user-defined variables
gtm_create_tag Create any tag type
gtm_create_trigger Create pageview, custom event, click triggers
gtm_create_variable Create Data Layer, URL, Auto-Event variables
gtm_create_ga4_tag Shortcut for GA4 config and event tags
gtm_create_meta_pixel_tag Shortcut for Meta Pixel tags
gtm_create_google_ads_conversion_tag Google Ads conversion + linker
gtm_delete_tag Remove tags
gtm_publish Create version and publish live

What We Built in One Session

36 Data Layer Variables

Transaction tracking, user identity, engagement metrics, UTM attribution — all as proper GTM Data Layer Variables that any tag can reference:

  • Ecommerce: transactionId, leadValue, planName, planValue, paymentMethod, couponCode
  • Identity: userId, workspaceId, clientSlug, accountType, daysSinceSignup
  • Engagement: toolName, agentType, skillName, messageCount, sessionCost, platformConnected
  • Attribution: utmSource, utmMedium, utmCampaign, utmContent, utmTerm, gclid, fbclid, referrer, landingPage
  • URL: Full URL, Path, Query string

22 Triggers

Pageview triggers for key pages, custom event triggers for data layer events, click triggers for phone numbers:

  • All Pages, Thank You Page, Demo Page
  • Custom events: lead_submitted, cta_click, form_start, form_submit, form_abandon, form_error, utm_captured, user_identified, outbound_click, service_viewed, pricing_viewed
  • Scroll depth: 25%, 50%, 75%, 100%
  • Time on page: 30s, 60s, 120s

28 Tags

16 native GA4 event tags (gaawe type) + 10 Meta Pixel tags + Conversion Linker + GA4 Config:

Every GA4 tag uses the native gaawe tag type with measurementIdOverride — not custom HTML. This means Google Tag Assistant recognizes them properly, they show up correctly in GA4 DebugView, and they benefit from GTM's built-in consent management.

The API Gotcha

One thing we learned: GA4 event tags use measurementIdOverride as the parameter key, not measurementId. The GTM API returns a cryptic error if you get this wrong:

vendorTemplate.parameter.measurementIdOverride: The value must not be empty.

Also: after publishing a workspace, GTM creates a new workspace automatically. Your next API calls need to target the new workspace path, not the old one.

Why This Matters

Manual GTM management doesn't scale. When you're managing tracking for multiple clients, each needing GA4 + Meta Pixel + Google Ads + data layer variables + conversion triggers — the GTM UI becomes a bottleneck.

With programmatic management, the agent handles it. Tell it what to track, it creates the tags, triggers, and variables, and publishes the container. The tracking infrastructure that used to require a dedicated analytics engineer now takes one conversation.

Frequently Asked Questions

Can you create GTM tags programmatically?

Yes. The Google Tag Manager API v2 allows you to create, update, delete, and publish tags, triggers, and variables. NXFLO uses this API to manage GTM containers directly from the agent — no manual interface needed.

What types of GTM tags can be created via API?

All types: GA4 Config (googtag), GA4 Events (gaawe), Custom HTML, Conversion Linker (gclidw), Google Ads Conversion (awct), and any vendor template tag supported by GTM.

Back to Blog