-
Notifications
You must be signed in to change notification settings - Fork 32
feat: add external handler through module options #13
base: master
Are you sure you want to change the base?
Conversation
Serialized function has many limits. What's the usecase of replacing handler? |
The handler is for handling manual GTM implementations using |
In this case, I think this line can be configurable to support dataLayer. Providing a sample use case (with dataLayer) can be useful. |
We can add a feature to support dataLayer With that in mind, how can we achieve this? Share your ideas. |
Can you please share an example custom handler? |
like this:
or directly pushing to dataLayer (not working, cause can't access global scope window):
|
We can add a new module option function googleOptimize(ctx, { experiment }) {
if (process.server || !experiment || !experiment.experimentID) {
return
}
<% if (options.eventHandler === 'ga') { %>
// https://developers.google.com/optimize/devguides/experiments
if (!window.ga) return
const exp = experiment.experimentID + '.' + experiment.$variantIndexes.join('-')
window.ga('set', 'exp', exp)
<% } else if (options.eventHandler === 'gtm') { %>
// TODO: Link to gtm docs
if (!ctx.$gtm) return
ctx.$gtm.execute({
expId: experiment.experimentId,
expVar: experiment.$activeVariants.join('-')
})
<% } else if (options.eventHandler === 'dataLayer') { %>
// TODO: Link to gtm docs
if (!window.dataLayer) return
window.dataLayer.push({
expId: experiment.experimentId,
expVar: experiment.$activeVariants.join('-')
})
<% } %>
} This is safer as we don't serialize function and also removes boilerplate from projects that need different event handling. |
@SasanFarrokh Would you please check Pooya's proposal and inform us? Thanks mate. |
Any update on this? We currently have Optimize set up via tag manager and this looks like it would fix our issues. |
@pi0 Do you think Sasan's work needs any further refinements or can we merge this? |
Serializing functions is not a nuxt recommended way. Other than suggestion above, modules for nuxt 2.9 are supporting |
Example for options (handler) file with < 2.9 backward support: nuxt-community/vuetify-module#86 |
Any update on this please? It would be really helpful :-) |
@SasanFarrokh Can you take a look at he vuetify example and see if we can implement it in our module? |
any updates here? |
Any updates? |
No description provided.