Skip to content

Commit

Permalink
fix(gatsby-plugin-google-analytics): Fix gatsby-node so we still have…
Browse files Browse the repository at this point in the history
… a warning on older gatsby versions (gatsbyjs#27495)
  • Loading branch information
MichaelDeBoey committed Oct 16, 2020
1 parent c6388c1 commit 9797828
Showing 1 changed file with 46 additions and 36 deletions.
82 changes: 46 additions & 36 deletions packages/gatsby-plugin-google-analytics/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,48 @@
exports.pluginOptionsSchema = ({ Joi }) =>
// TODO: make sure that trackingId gets required() when releasing a major version
Joi.object({
trackingId: Joi.string().description(
`The property ID; the tracking code won't be generated without it`
),
head: Joi.boolean()
.default(false)
.description(
`Defines where to place the tracking script - \`true\` in the head and \`false\` in the body`
if (process.env.GATSBY_EXPERIMENTAL_PLUGIN_OPTION_VALIDATION) {
exports.pluginOptionsSchema = ({ Joi }) =>
// TODO: make sure that trackingId gets required() when releasing a major version
Joi.object({
trackingId: Joi.string().description(
`The property ID; the tracking code won't be generated without it`
),
anonymize: Joi.boolean().default(false),
respectDNT: Joi.boolean().default(false),
exclude: Joi.array()
.items(Joi.string())
.default([])
.description(`Avoids sending pageview hits from custom paths`),
pageTransitionDelay: Joi.number()
.default(0)
.description(
`Delays sending pageview hits on route update (in milliseconds)`
head: Joi.boolean()
.default(false)
.description(
`Defines where to place the tracking script - \`true\` in the head and \`false\` in the body`
),
anonymize: Joi.boolean().default(false),
respectDNT: Joi.boolean().default(false),
exclude: Joi.array()
.items(Joi.string())
.default([])
.description(`Avoids sending pageview hits from custom paths`),
pageTransitionDelay: Joi.number()
.default(0)
.description(
`Delays sending pageview hits on route update (in milliseconds)`
),
optimizeId: Joi.string().description(
`Enables Google Optimize using your container Id`
),
optimizeId: Joi.string().description(
`Enables Google Optimize using your container Id`
),
experimentId: Joi.string().description(
`Enables Google Optimize Experiment ID`
),
variationId: Joi.string().description(
`Set Variation ID. 0 for original 1,2,3....`
),
defer: Joi.boolean().description(
`Defers execution of google analytics script after page load`
),
sampleRate: Joi.number(),
siteSpeedSampleRate: Joi.number(),
cookieDomain: Joi.string(),
})
experimentId: Joi.string().description(
`Enables Google Optimize Experiment ID`
),
variationId: Joi.string().description(
`Set Variation ID. 0 for original 1,2,3....`
),
defer: Joi.boolean().description(
`Defers execution of google analytics script after page load`
),
sampleRate: Joi.number(),
siteSpeedSampleRate: Joi.number(),
cookieDomain: Joi.string(),
})
} else {
exports.onPreInit = ({ reporter }, { trackingId } = {}) => {
if (!trackingId) {
reporter.warn(
`The Google Analytics plugin requires a tracking ID. Did you mean to add it?`
)
}
}
}

0 comments on commit 9797828

Please sign in to comment.