8000 devops(insuit): manage GTM and GA4 as code in CI by landsman · Pull Request #500 · landsman/homelab · GitHub
[go: up one dir, main page]

Skip to content

devops(insuit): manage GTM and GA4 as code in CI - #500

Open
landsman wants to merge 22 commits into
mainfrom
devops/insuit-gtm-as-code
Open

landsman wants to merge 22 commits into
mainfrom
devops/insuit-gtm-as-code

Conversation

@landsman
Copy link
Copy Markdown
Owner

GTM and GA4 configuration now lives in insuit/analytics/analytics.yaml: @stackmade/gtm-as-code diffs it against the live container and property, Terraform-style.

  • bun run gtm:validate, gtm:plan and gtm:apply scripts, added as a dev dependency alongside the rest of the stack.
  • Pull requests run validate + plan and post the plan as a sticky comment, so a change is reviewable before it reaches the container.
  • On main, a gtm job applies after the site deploy, gated by the production environment.
  • Both jobs skip when the Google IDs or credentials are absent, so the pipeline stays green before the one-time setup.

The setup — vars GTM_ACCOUNT_ID, GTM_CONTAINER_ID, GA4_PROPERTY_ID and Workload Identity Federation secrets — is documented in the insuit README. gtm-code validate passes under bun.

Add @stackmade/gtm-as-code to the insuit project with bun scripts and an analytics/ config. On PRs the CI runs validate and plan against the live GTM/GA4 and posts the diff as a comment; on main it applies after the site deploy, gated by the production environment. Jobs skip gracefully when the Google credentials/IDs are not configured.
@github-actions

This comment has been minimized.

Comment thread .github/workflows/insuit-ci.yml Resolved
Comment thread .github/workflows/insuit-ci.yml Resolved
Comment thread .github/workflows/insuit-deploy.yml Resolved
Comment thread .github/workflows/insuit-deploy.yml Resolved
Comment thread .github/workflows/insuit-deploy.yml Resolved
Comment thread .github/workflows/insuit-ci.yml Resolved
Comment thread .github/workflows/insuit-ci.yml Resolved
Comment thread .github/workflows/insuit-deploy.yml Resolved
Comment thread .github/workflows/insuit-deploy.yml Resolved
Comment thread .github/workflows/insuit-ci.yml Resolved
…eploy in its job

gtm-code plan exits 2 on changes, which failed the PR job before it could comment; apply only stages a draft, so nothing went live without a publish. The plan job signs in as a read-only account, and a changed GA4 state.json fails the deploy instead of being lost with the runner.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

…ites

Other repos call landsman/homelab/.github/workflows/gtm.yml at a pinned sha; insuit calls it locally. Each step is three lines of shell or less, so gtm.sh went back inline: a script beside one site would not travel with the workflow.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

…ml to the site root

GitHub only finds a reusable workflow directly in .github/workflows/, so gtm/ holds its README, which the config points to. At the site root gtm-code finds analytics.yaml without -c, and the preview no longer rebuilds for it.
@github-actions

This comment has been minimized.

…eside it

Everything GTM sits in .github/actions/gtm: the action, its README and the rules for which changes it acts on. .github/actions/changes reads those rules and outputs one value per feature, so a site's changes job no longer carries its own path list.
@github-actions

This comment has been minimized.

They address the container in the Tag Manager API and open nothing without granted access, so they need no variable. The GTM action loses its id inputs: a site's config holds them, or reads one from the job's env.
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

…ariable gone

With every id in analytics.yaml, the gtm jobs no longer wait on a repo variable and .env.analytics has nothing left to hold. The setup now starts with where each id is found.
@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown

Feature tests failed on f22783d.
Cucumber report, readable for 24 hours: https://reports.cucumber.io/reports/e9c7c4dc-8498-4331-bab8-846ada5823f5

The contact page pushes contact_email, which analytics.yaml turns into a GTM trigger, a GA4 event tag and a key event. The same change keeps event data 14 months instead of GA4's two, and switches off the stream's site search and form tracking, which this site has nothing for.
@github-actions

This comment has been minimized.

The page pushes social_click with the network, and analytics.yaml declares it, with network as a GA4 dimension. GA4's own outbound clicks stay on for every other link that leaves the site; it is a different event, so nothing counts twice.
@github-actions

This comment has been minimized.

…yaml

gtm-code generate types every event the config declares, so a misspelt name or a missing parameter fails the typecheck instead of losing data; make qa fails when the generated file lags the config. The contact address now sends generate_lead, the name GA4's lead reports count.
@github-actions

This comment has been minimized.

bunx hands a node shebang to Node when it is installed; bun run goes through bunfig's run.bun like every other script here.
@github-actions

This comment has been minimized.

…TM triggers

gtm-code 0.9.2 cannot give a click trigger a condition, so the contact page pushes its own events. The caveat holds the YAML that replaces them once it can.
@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown

insuit.cz preview: https://devops-insuit-gtm-as-code.insuit-preview.pages.dev (commit 1c3532a)

This branch was previously deployed

1 inactive deployment
production — 1c3532a9 Deployed Oct 24, 2026 by landsman via preview #400
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0