Skip to content

Add Google Tag Manager first-party integration#262

Draft
prk-Jr wants to merge 11 commits intomainfrom
feat/gtm-integration
Draft

Add Google Tag Manager first-party integration#262
prk-Jr wants to merge 11 commits intomainfrom
feat/gtm-integration

Conversation

@prk-Jr
Copy link
Collaborator

@prk-Jr prk-Jr commented Feb 9, 2026

Scripts like GTM and GA4 are often blocked by ad blockers or privacy extensions when loaded from third-party domains, leading to data loss. Third-party cookie deprecation further limits tracking durability.

This change transparently proxies GTM scripts and analytics beacons through the Trusted Server, establishing a first-party context. It automatically rewrites HTML tags and script content to point to local proxy endpoints, bypassing blockers and extending cookie life.

Includes:

  • Proxy endpoints for gtm.js and /collect with optimal caching (1h TTL) and strict validation
  • Content rewriting to redirect internal GTM calls to the local proxy
  • Configuration validation to ensure safe upstream handling
  • Comprehensive testing, including unit and integration tests covering configuration, rewriting logic, and header validation

Resolves: #224

Scripts like GTM and GA4 are often blocked by ad blockers and privacy extensions when loaded from third-party domains, leading to data loss. Third-party cookie deprecation further limits tracking durability.

This change proxies GTM scripts and analytics beacons through the Trusted Server, establishing a first-party context. It automatically rewrites HTML tags and script content to point to local proxy endpoints, bypassing blockers and extending cookie life.

Includes:

Proxy endpoints for gtm.js and /collect
Content rewriting for redirecting internal GTM calls
Configuration and integration tests

Resolves: #224
@prk-Jr prk-Jr self-assigned this Feb 9, 2026
@prk-Jr prk-Jr marked this pull request as draft February 9, 2026 09:20
@prk-Jr prk-Jr marked this pull request as ready for review February 9, 2026 10:23
@prk-Jr prk-Jr marked this pull request as draft February 9, 2026 10:24
Adds comprehensive tests for:
- GTM configuration parsing and default values
- HTML processor pipeline integration
- Response body rewriting logic
@prk-Jr prk-Jr marked this pull request as ready for review February 9, 2026 11:13
Copy link
Collaborator

@aram356 aram356 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔧 Please make sure checks pass before assigning to review.

@prk-Jr prk-Jr requested a review from aram356 February 10, 2026 12:20
Copy link
Collaborator

@aram356 aram356 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good start. Need to address specific items and the following.

Duplicated rewrite logic across three places

The GTM URL rewriting logic exists in three separate methods: rewrite_gtm_script(), IntegrationAttributeRewriter::rewrite(), and IntegrationScriptRewriter::rewrite(). Each handles a slightly different set of patterns. This is error-prone — a new URL pattern needs to be added in multiple places.

…, set default enablement to false, and update documentation for handling
@prk-Jr prk-Jr requested a review from aram356 February 13, 2026 09:33
@prk-Jr prk-Jr requested a review from aram356 February 16, 2026 07:56
]
}

async fn handle(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POST analytics payloads are dropped while proxying GTM

Take a look at the failing tests I added here.

feat/gtm-integration...review/gtm-integration

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ChristianPavilonis, let me look into it.

- **Bypass Ad Blockers**: Serving scripts from a first-party domain can prevent them from being blocked by some ad blockers and privacy extensions.
- **Extended Cookie Life**: First-party cookies set by these scripts are more durable in environments like Safari (ITP).
- **Performance**: Utilize edge caching for scripts.
- **Privacy Control**: Strips client IP addresses before forwarding data to Google.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't true. IP still forwards.

see other.

feat/gtm-integration...review/gtm-integration

…nctions, improving request configuration for beacons and scripts
@prk-Jr prk-Jr marked this pull request as draft February 16, 2026 16:07
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.

As publisher I want to host GTM in publisher domain

3 participants