Thanks for these great Analytics packages!
I would like to disable them, until the user accept my Cookie consent (as much as I know, this is the law in EU). I wish to use this npm package, which hase an onAccept prop.
So I set up my frontity.settings.js
file, as the following:
const settings = {
name: 'MyProjectName',
state: {
frontity: {
...
},
analytics: {
pageviews: {
googleAnalytics: false
},
events: {
googleAnalytics: false
}
}
},
packages: [
...
{
name: '@frontity/google-analytics',
state: {
googleAnalytics: {
trackingId: 'UA-123456789-1'
}
}
},
...
'@frontity/yoast'
]
}
export default settings
And I created an action in the /myTheme/src/index.js
file:
import Theme from './components'
const myTheme = {
name: 'myThemeName',
roots: {
theme: Theme
},
...
// Actions are functions that modify the state or deal with other parts of
// Frontity like libraries.
actions: {
theme: {
...
},
analytics: {
enableAnalytics: ({ state }) => {
state.analytics.pageviews.googleAnalytics = true
state.analytics.events.googleAnalytics = true
}
}
},
...
}
export default chakraTheme
I can call it in my components/index.js
file, as following:
<CookieConsent
onAccept={() => { actions.analytics.enableAnalytics() }}
>
It’s working great! My only problem is, that even these steps, google analytics cookies will be created on pageload .
Any suggestion?