|
1 |
| -exports.pluginOptionsSchema = ({ Joi }) => |
2 |
| - // TODO: make sure that trackingId gets required() when releasing a major version |
3 |
| - Joi.object({ |
4 |
| - trackingId: Joi.string().description( |
5 |
| - `The property ID; the tracking code won't be generated without it` |
6 |
| - ), |
7 |
| - head: Joi.boolean() |
8 |
| - .default(false) |
9 |
| - .description( |
10 |
| - `Defines where to place the tracking script - \`true\` in the head and \`false\` in the body` |
| 1 | +if (process.env.GATSBY_EXPERIMENTAL_PLUGIN_OPTION_VALIDATION) { |
| 2 | + exports.pluginOptionsSchema = ({ Joi }) => |
| 3 | + // TODO: make sure that trackingId gets required() when releasing a major version |
| 4 | + Joi.object({ |
| 5 | + trackingId: Joi.string().description( |
| 6 | + `The property ID; the tracking code won't be generated without it` |
11 | 7 | ),
|
12 |
| - anonymize: Joi.boolean().default(false), |
13 |
| - respectDNT: Joi.boolean().default(false), |
14 |
| - exclude: Joi.array() |
15 |
| - .items(Joi.string()) |
16 |
| - .default([]) |
17 |
| - .description(`Avoids sending pageview hits from custom paths`), |
18 |
| - pageTransitionDelay: Joi.number() |
19 |
| - .default(0) |
20 |
| - .description( |
21 |
| - `Delays sending pageview hits on route update (in milliseconds)` |
| 8 | + head: Joi.boolean() |
| 9 | + .default(false) |
| 10 | + .description( |
| 11 | + `Defines where to place the tracking script - \`true\` in the head and \`false\` in the body` |
| 12 | + ), |
| 13 | + anonymize: Joi.boolean().default(false), |
| 14 | + respectDNT: Joi.boolean().default(false), |
| 15 | + exclude: Joi.array() |
| 16 | + .items(Joi.string()) |
| 17 | + .default([]) |
| 18 | + .description(`Avoids sending pageview hits from custom paths`), |
| 19 | + pageTransitionDelay: Joi.number() |
| 20 | + .default(0) |
| 21 | + .description( |
| 22 | + `Delays sending pageview hits on route update (in milliseconds)` |
| 23 | + ), |
| 24 | + optimizeId: Joi.string().description( |
| 25 | + `Enables Google Optimize using your container Id` |
22 | 26 | ),
|
23 |
| - optimizeId: Joi.string().description( |
24 |
| - `Enables Google Optimize using your container Id` |
25 |
| - ), |
26 |
| - experimentId: Joi.string().description( |
27 |
| - `Enables Google Optimize Experiment ID` |
28 |
| - ), |
29 |
| - variationId: Joi.string().description( |
30 |
| - `Set Variation ID. 0 for original 1,2,3....` |
31 |
| - ), |
32 |
| - defer: Joi.boolean().description( |
33 |
| - `Defers execution of google analytics script after page load` |
34 |
| - ), |
35 |
| - sampleRate: Joi.number(), |
36 |
| - siteSpeedSampleRate: Joi.number(), |
37 |
| - cookieDomain: Joi.string(), |
38 |
| - }) |
| 27 | + experimentId: Joi.string().description( |
| 28 | + `Enables Google Optimize Experiment ID` |
| 29 | + ), |
| 30 | + variationId: Joi.string().description( |
| 31 | + `Set Variation ID. 0 for original 1,2,3....` |
| 32 | + ), |
| 33 | + defer: Joi.boolean().description( |
| 34 | + `Defers execution of google analytics script after page load` |
| 35 | + ), |
| 36 | + sampleRate: Joi.number(), |
| 37 | + siteSpeedSampleRate: Joi.number(), |
| 38 | + cookieDomain: Joi.string(), |
| 39 | + }) |
| 40 | +} else { |
| 41 | + exports.onPreInit = ({ reporter }, { trackingId } = {}) => { |
| 42 | + if (!trackingId) { |
| 43 | + reporter.warn( |
| 44 | + `The Google Analytics plugin requires a tracking ID. Did you mean to add it?` |
| 45 | + ) |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments