Skip to content

Commit

Permalink
feat(gatsby-plugin-google-tagmanager): Allow to place the GTM script … (
Browse files Browse the repository at this point in the history
#13424)

* feat(gatsby-plugin-google-tagmanager): Allow to place the GTM script at the end of the <body> tag

* fix: Remove a ;

* fix(gatsby-plugin-google-tagmanager): Flip over the head/body condition
  • Loading branch information
NoriSte authored and sidharthachatterjee committed Apr 18, 2019
1 parent 44e7067 commit 0b56c3b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
5 changes: 5 additions & 0 deletions packages/gatsby-plugin-google-tagmanager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <head> (as suggested by Google)
// or append it to the <body> (making it non-blocking).
// Defaults to false meaning GTM will be added in the <head> (again, as suggested by Google).
addTagInBody: false,
},
},
]
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-google-tagmanager/package.json
Original file line number Diff line number Diff line change
@@ -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 <thijs@vauxlab.com>",
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
Expand Down
9 changes: 6 additions & 3 deletions packages/gatsby-plugin-google-tagmanager/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -18,7 +18,10 @@ exports.onRenderBody = (
`
: ``

setHeadComponents([
const setComponents = pluginOptions.addTagInBody
? setPostBodyComponents
: setHeadComponents
setComponents([
<script
key="plugin-google-tagmanager"
dangerouslySetInnerHTML={{
Expand Down

0 comments on commit 0b56c3b

Please sign in to comment.