Skip to content

Commit

Permalink
feat(gatsby-plugin-google-analytics): add head option (#3995)
Browse files Browse the repository at this point in the history
Add head option to configure whether scrip tag should be put in the
body (by default, same as previously) or inside of the head.
closes #2894
  • Loading branch information
Sekhmet authored and KyleAMathews committed Feb 12, 2018
1 parent 14babb3 commit 10e6702
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions packages/gatsby-plugin-google-analytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ plugins: [
resolve: `gatsby-plugin-google-analytics`,
options: {
trackingId: "YOUR_GOOGLE_ANALYTICS_TRACKING_ID",
// Puts tracking script in the head instead of the body
head: false,
// Setting this parameter is optional
anonymize: true,
},
Expand Down
10 changes: 8 additions & 2 deletions packages/gatsby-plugin-google-analytics/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from "react"

exports.onRenderBody = ({ setPostBodyComponents }, pluginOptions) => {
exports.onRenderBody = (
{ setHeadComponents, setPostBodyComponents },
pluginOptions
) => {
if (process.env.NODE_ENV === `production`) {
return setPostBodyComponents([
const setComponents = pluginOptions.head
? setHeadComponents
: setPostBodyComponents
return setComponents([
<script
key={`gatsby-plugin-google-analytics`}
dangerouslySetInnerHTML={{
Expand Down

0 comments on commit 10e6702

Please sign in to comment.