/
gatsby-node.js
42 lines (40 loc) · 1.35 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/** @type {import('gatsby').GatsbyNode["onPreInit"]} */
exports.onPreInit = (args, options) => {
if (options.defaultDataLayer) {
options.defaultDataLayer = {
type: typeof options.defaultDataLayer,
value: options.defaultDataLayer,
}
if (options.defaultDataLayer.type === `function`) {
options.defaultDataLayer.value = options.defaultDataLayer.value.toString()
}
}
}
exports.pluginOptionsSchema = ({ Joi }) =>
Joi.object({
id: Joi.string().description(
`Google Tag Manager ID that can be found in your Tag Manager dashboard.`
),
includeInDevelopment: Joi.boolean()
.default(false)
.description(
`Include Google Tag Manager when running in development mode.`
),
defaultDataLayer: Joi.object()
.default(null)
.description(
`Data layer to be set before Google Tag Manager is loaded. Should be an object or a function.`
),
gtmAuth: Joi.string().description(
`Google Tag Manager environment auth string.`
),
gtmPreview: Joi.string().description(
`Google Tag Manager environment preview name.`
),
dataLayerName: Joi.string().description(`Data layer name.`),
routeChangeEventName: Joi.string()
.default(`gatsby-route-change`)
.description(
`Name of the event that is triggered on every Gatsby route change.`
),
})