Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add url to google tag manager #1

Open
wants to merge 3 commits into
base: canary
Choose a base branch
from

Conversation

thinkjrs
Copy link
Member

@thinkjrs thinkjrs commented Apr 11, 2024

From my seat it looks like two very simple changes, entirely non-breaking:

  1. Update GTMParams type:

In the /packages/third-parties/src/types/google.ts file add an optional url parameter to GTMParams.

export type GTMParams = {
  gtmId: string
  dataLayer?: string[]
  dataLayerName?: string
  auth?: string
  preview?: string
  url?: string // new
}
  1. Update the /packages/third-parties/src/google/gtm.tsx file add the url parameter only if it is included:
  const { gtmId, dataLayerName = 'dataLayer', auth, preview, dataLayer, url } = props
  const gtmLayer = dataLayerName !== 'dataLayer' ? `&l=${dataLayerName}` : ''
  const gtmAuth = auth ? `&gtm_auth=${auth}` : ''
  const gtmPreview = preview ? `&gtm_preview=${preview}&gtm_cookies_win=x` : ''
  const gtmUrl = url ? url : 'https://www.googletagmanager.com' // new

// second script component returned now uses gtmUrl which defaults to exactly the same url as was hardcoded before
      <Script
        id="_next-gtm"
        data-ntpc="GTM"
        src={`${gtmUrl}/gtm.js?id=${gtmId}${gtmLayer}${gtmAuth}${gtmPreview}`}
      />

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