diff --git a/README.md b/README.md index 1661e20..c860429 100644 --- a/README.md +++ b/README.md @@ -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, }, diff --git a/package.json b/package.json index e840830..7003e55 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,20 @@ { "name": "gatsby-plugin-google-analytics", "description": "Gatsby plugin to add google analytics onto a site", - "version": "1.0.16", + "version": "1.0.19", "author": "Kyle Mathews ", + "bugs": { + "url": "https://github.com/gatsbyjs/gatsby/issues" + }, + "dependencies": { + "@babel/runtime": "^7.0.0-beta.38" + }, "devDependencies": { "@babel/cli": "^7.0.0-beta.38", "@babel/core": "^7.0.0-beta.38", "cross-env": "^5.0.5" }, + "homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-google-analytics#readme", "keywords": [ "gatsby", "gatsby-plugin", @@ -15,15 +22,16 @@ ], "license": "MIT", "main": "index.js", - "scripts": { - "build": "babel src --out-dir . --ignore **/__tests__/**", - "watch": "babel -w src --out-dir . --ignore **/__tests__/**", - "prepublish": "cross-env NODE_ENV=production npm run build" - }, - "dependencies": { - "@babel/runtime": "^7.0.0-beta.38" - }, "peerDependencies": { "gatsby": ">1.0.0 || >2.0.0-alpha" + }, + "repository": { + "type": "git", + "url": "https://github.com/gatsbyjs/gatsby.git" + }, + "scripts": { + "build": "babel src --out-dir . --ignore __tests__", + "prepublish": "cross-env NODE_ENV=production npm run build", + "watch": "babel -w src --out-dir . --ignore __tests__" } } diff --git a/src/gatsby-browser.js b/src/gatsby-browser.js index 42e22f0..f7e5891 100644 --- a/src/gatsby-browser.js +++ b/src/gatsby-browser.js @@ -1,10 +1,7 @@ exports.onRouteUpdate = function({ location }) { // Don't track while developing. if (process.env.NODE_ENV === `production` && typeof ga === `function`) { - // Wait for the title update (see #2478) - setTimeout(() => { - window.ga(`set`, `page`, (location || {}).pathname) - window.ga(`send`, `pageview`) - }, 0) + window.ga(`set`, `page`, (location || {}).pathname) + window.ga(`send`, `pageview`) } } diff --git a/src/gatsby-ssr.js b/src/gatsby-ssr.js index 7e363d3..6625543 100644 --- a/src/gatsby-ssr.js +++ b/src/gatsby-ssr.js @@ -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([