diff --git a/packages/gatsby-plugin-google-tagmanager/README.md b/packages/gatsby-plugin-google-tagmanager/README.md index 7a5b64c666205..2d39aa4818651 100644 --- a/packages/gatsby-plugin-google-tagmanager/README.md +++ b/packages/gatsby-plugin-google-tagmanager/README.md @@ -24,6 +24,11 @@ plugins: [ gtmAuth: "YOUR_GOOGLE_TAGMANAGER_ENVIROMENT_AUTH_STRING", gtmPreview: "YOUR_GOOGLE_TAGMANAGER_ENVIROMENT_PREVIEW_NAME", dataLayerName: "YOUR_DATA_LAYER_NAME", + + // Whether to put the GTM script into the (as suggested by Google) + // or append it to the (making it non-blocking). + // Defaults to false meaning GTM will be added in the (again, as suggested by Google). + addTagInBody: false, }, }, ] diff --git a/packages/gatsby-plugin-google-tagmanager/package.json b/packages/gatsby-plugin-google-tagmanager/package.json index 1ccb0a849c8bc..d8b22033c8616 100644 --- a/packages/gatsby-plugin-google-tagmanager/package.json +++ b/packages/gatsby-plugin-google-tagmanager/package.json @@ -1,7 +1,7 @@ { "name": "gatsby-plugin-google-tagmanager", "description": "Gatsby plugin to add google tagmanager onto a site", - "version": "2.0.13", + "version": "2.1.0", "author": "Thijs Koerselman ", "bugs": { "url": "https://github.com/gatsbyjs/gatsby/issues" diff --git a/packages/gatsby-plugin-google-tagmanager/src/gatsby-ssr.js b/packages/gatsby-plugin-google-tagmanager/src/gatsby-ssr.js index 99bdd060719e7..ef03942a1a448 100644 --- a/packages/gatsby-plugin-google-tagmanager/src/gatsby-ssr.js +++ b/packages/gatsby-plugin-google-tagmanager/src/gatsby-ssr.js @@ -1,8 +1,8 @@ -import React from "react" import { oneLine, stripIndent } from "common-tags" +import React from "react" exports.onRenderBody = ( - { setHeadComponents, setPreBodyComponents }, + { setHeadComponents, setPreBodyComponents, setPostBodyComponents }, pluginOptions ) => { if ( @@ -18,7 +18,10 @@ exports.onRenderBody = ( ` : `` - setHeadComponents([ + const setComponents = pluginOptions.addTagInBody + ? setPostBodyComponents + : setHeadComponents + setComponents([