From 8882a0b726c071c0fa3355104292ae3af01ee812 Mon Sep 17 00:00:00 2001 From: Thomas Kunwar <20840228+yathomasi@users.noreply.github.com> Date: Thu, 27 Jun 2024 22:25:50 +0545 Subject: [PATCH] feat: gtm setup (#5268) --- gatsby-config.js | 20 ++++++++++++++++++++ package.json | 1 + yarn.lock | 22 ++++++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/gatsby-config.js b/gatsby-config.js index 990236c599..6f80069704 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -117,6 +117,26 @@ const plugins = [ } ] +if (process.env.GATSBY_GTM_ID) { + plugins.push({ + resolve: `gatsby-plugin-google-tagmanager`, + options: { + id: process.env.GATSBY_GTM_ID, + + // Include GTM in development. + // + // Defaults to false meaning GTM will only be loaded in production. + includeInDevelopment: process.env.GTM_INCLUDE_IN_DEV === `true`, + + // datalayer to be set before GTM is loaded + // should be an object or a function that is executed in the browser + // + // Defaults to null + defaultDataLayer: { platform: `gatsby` } + } + }) +} + if (process.env.ANALYZE) { plugins.push({ resolve: 'gatsby-plugin-webpack-bundle-analyser-v2' diff --git a/package.json b/package.json index fb5ced9733..b0c2d17599 100644 --- a/package.json +++ b/package.json @@ -54,6 +54,7 @@ "dotenv": "16.4.5", "gatsby": "5.13.6", "gatsby-plugin-catch-links": "5.13.1", + "gatsby-plugin-google-tagmanager": "5.13.1", "gatsby-plugin-image": "3.13.1", "gatsby-plugin-manifest": "5.13.1", "gatsby-plugin-postcss": "6.13.1", diff --git a/yarn.lock b/yarn.lock index 1e98083ce3..cf8bd5e474 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12638,6 +12638,20 @@ __metadata: languageName: node linkType: hard +"gatsby-plugin-google-tagmanager@npm:5.13.1": + version: 5.13.1 + resolution: "gatsby-plugin-google-tagmanager@npm:5.13.1" + dependencies: + "@babel/runtime": "npm:^7.20.13" + web-vitals: "npm:^1.1.2" + peerDependencies: + gatsby: ^5.0.0-next + react: ^18.0.0 || ^0.0.0 + react-dom: ^18.0.0 || ^0.0.0 + checksum: 10c0/f375ab868ff5c8acd32024b852bee6f3dc3a0b0849a9d67dad78efdfa55be12a60b7613aa49f51a796a41877ace36b3e6a92eae3295073fd12326857da36d78d + languageName: node + linkType: hard + "gatsby-plugin-image@npm:3.13.1, gatsby-plugin-image@npm:^3.13.1": version: 3.13.1 resolution: "gatsby-plugin-image@npm:3.13.1" @@ -24991,6 +25005,13 @@ __metadata: languageName: node linkType: hard +"web-vitals@npm:^1.1.2": + version: 1.1.2 + resolution: "web-vitals@npm:1.1.2" + checksum: 10c0/9521ea2e8ca2e4446ba8e3d5430b0c9a9a07e0d6f468a90dc5fab2bab524fb1a699f3874ea392c9e35a63dcf3651b40130d58ebd78e53a406cb9622049bf1403 + languageName: node + linkType: hard + "webidl-conversions@npm:^3.0.0": version: 3.0.1 resolution: "webidl-conversions@npm:3.0.1" @@ -25158,6 +25179,7 @@ __metadata: eslint-plugin-react: "npm:7.34.3" gatsby: "npm:5.13.6" gatsby-plugin-catch-links: "npm:5.13.1" + gatsby-plugin-google-tagmanager: "npm:5.13.1" gatsby-plugin-image: "npm:3.13.1" gatsby-plugin-manifest: "npm:5.13.1" gatsby-plugin-postcss: "npm:6.13.1"