Replies: 1 comment 2 replies
-
In the meantime users can get the Note that users will need to add this as a client component in their apps, as my current lib build system removes For example: 'use client'
import React from 'react'
import { GoogleTagManager as GTM } from '@tincre/next-gtm-server'
export function GoogleTagManager(props: { gtmId: string; url?: string /* add what you need here */}) {
return <GTM {...props} />
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
This is necessary for a server side Google Tag Manager setup.
I have this implemented already Tincre#1.
Non-Goals
No response
Background
Currently we can improve the GTM experience w/Next.js via the
third-parties/google
lib.A typical implementation is usually something like the following:
This serves the google tag manager from
https://www.googletagmanager.com
. However, for server-side setups this url should point elsewhere, typically a first party domain or subdomain. For example,https://metrics.tincre.com
, rather thanhttps://www.googletagmanager.com
.Here's Google's setup instructions within their tagmanager application:
Proposal
I've already got this ready to go and will/can submit a PR with the exact changes listed below. Here's the PR in my forked repository: Tincre#1
From my seat it looks like two very simple changes, entirely non-breaking:
GTMParams
type:In the /packages/third-parties/src/types/google.ts file add an optional
url
parameter toGTMParams
.url
parameter only if it is included:docs/02-app/01-building-your-application/06-optimizing/12-third-party-libraries.mdx
:Using a custom server URL
If you have a server-side tag manager deployment, you can customize the URL by passing i
n a
url
parameter. The component useshttps://www.googletagamanager.com
by default.Beta Was this translation helpful? Give feedback.
All reactions