-
Notifications
You must be signed in to change notification settings - Fork 68
/
gatsby-browser.js
43 lines (36 loc) · 1.6 KB
/
gatsby-browser.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
43
import { defaultOptions } from "./default-options"
import { initializeAndTrack } from './index'
import merge from "lodash/merge"
// init
export const onClientEntry = (_, pluginOptions = {}) => {
window.gatsbyPluginGDPRCookiesGoogleAnalyticsAdded = false
window.gatsbyPluginGDPRCookiesGoogleTagManagerAdded = false
window.gatsbyPluginGDPRCookiesFacebookPixelAdded = false
window.gatsbyPluginGDPRCookiesTikTokPixelAdded = false
window.gatsbyPluginGDPRCookiesHotjarAdded = false
window.gatsbyPluginGDPRCookiesChatwootAdded = false
window.gatsbyPluginGDPRCookiesLinkedinAdded = false
window.gatsbyPluginGDPRCookiesGoogleAnalyticsInitialized = false
window.gatsbyPluginGDPRCookiesGoogleTagManagerInitialized = false
window.gatsbyPluginGDPRCookiesFacebookPixelInitialized = false
window.gatsbyPluginGDPRCookiesTikTokPixelInitialized = false
window.gatsbyPluginGDPRCookiesHotjarInitialized = false
window.gatsbyPluginGDPRCookiesLinkedinInitialized = false
// google tag manager setup
const { googleTagManager } = pluginOptions
if (googleTagManager && googleTagManager.defaultDataLayer) {
googleTagManager.defaultDataLayer = {
type: typeof googleTagManager.defaultDataLayer,
value: googleTagManager.defaultDataLayer,
}
if (googleTagManager.defaultDataLayer.type === `function`) {
googleTagManager.defaultDataLayer.value = googleTagManager.defaultDataLayer.value.toString()
}
}
const options = merge(defaultOptions, pluginOptions)
window.gatsbyPluginGDPRCookiesOptions = options
}
// track
export const onRouteUpdate = ({ location }) => {
initializeAndTrack(location)
}