diff --git a/packages/third-parties/package.json b/packages/third-parties/package.json index 4a56a7b524741..c515df8ea467a 100644 --- a/packages/third-parties/package.json +++ b/packages/third-parties/package.json @@ -1,7 +1,6 @@ { "name": "@next/third-parties", "version": "13.5.6-canary.3", - "private": true, "repository": { "url": "vercel/next.js", "directory": "packages/third-parties" diff --git a/packages/third-parties/src/google/GoogleMapsEmbed.tsx b/packages/third-parties/src/google/google-maps-embed.tsx similarity index 100% rename from packages/third-parties/src/google/GoogleMapsEmbed.tsx rename to packages/third-parties/src/google/google-maps-embed.tsx diff --git a/packages/third-parties/src/google/gtm.tsx b/packages/third-parties/src/google/gtm.tsx new file mode 100644 index 0000000000000..f8e5462784616 --- /dev/null +++ b/packages/third-parties/src/google/gtm.tsx @@ -0,0 +1,68 @@ +'use client' +// TODO: Evaluate import 'client only' +import React from 'react' +import Script from 'next/script' + +declare global { + interface Window { + dataLayer?: Object[] + [key: string]: any + } +} + +type GTMParams = { + gtmId: string + dataLayer: string[] + dataLayerName: string + auth: string + preview: string +} + +let currDataLayerName: string | undefined = undefined + +export function GoogleTagManager(props: GTMParams) { + const { gtmId, dataLayerName = 'dataLayer', auth, preview, dataLayer } = props + + if (currDataLayerName === undefined) { + currDataLayerName = dataLayerName + } + + const gtmLayer = dataLayerName !== 'dataLayer' ? `$l=${dataLayerName}` : '' + const gtmAuth = auth ? `>m_auth=${auth}` : '' + const gtmPreview = preview ? `>m_preview=${preview}>m_cookies_win=x` : '' + + return ( + <> +