Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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