nuxt-community / google-optimize-module

SSR friendly Google Optimize module for Nuxt.js
MIT License
215 stars 32 forks source link

feat: add GTM handler and options #43

Open eljass opened 3 years ago

eljass commented 3 years ago

This PR is inspired from #13. That PR seems inactive so this will address the need for GTM integration.

Adds the possibility to use @nuxtjs/gtm-module or custom tag manager implementation with the possibility to rename used dataLayer variable.

This PR adds three options to implement sending experiment info:

farzadso commented 3 years ago

@eljass I would appreciate it if you could also add tests for these changes.

eljass commented 3 years ago

@farzadso I would but I don't really know how to test other libraries such as $gtm or global variables such as ga() or dataLayerwith jest

eljass commented 3 years ago

It occurs to me that this is not probably necessary as the user could write a plugin which handles sending experiment with preferred way? So should we just introduce an option to disable ga() event from firing on load?

Docs could then explain how to send a preferred event from the plugin.

For example GTM module would be

// plugins/google-optimize.js
export default function ({ $exp, $gtm }) {
  const exp = experiment.experimentID + '.' + experiment.$variantIndexes.join('-')
  $gtm.push({ exp })
}
// nuxt.conifg.js
export default {
  ...
  googleOptimize: {
    experimentsDir: '~/experiments',
    maxAge: 60 * 60 * 24 * 7, // 1 Week
    pushPlugin: true,
    plugins: ['~/plugins/google-optimize.js'],
    excludeBots: true,
    botExpression: /(bot|spider|crawler)/i
  }
}

Would it be enough then to add option to disable ga event?

dominik-wbz commented 2 years ago

Hello, can we merge this please? I'm also interested in using GTM instead of separate GA implementation @farzadso

mmeester commented 2 years ago

Since this repo seems to be unmaintained I've created a fork of @eljass his code and created a new package on npm nuxt-google-optimize-next

https://www.npmjs.com/package/nuxt-google-optimize-next