Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin): add support for Google Analytics 4 (gtag) #138

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Abbondanzo
Copy link

@Abbondanzo Abbondanzo commented Dec 1, 2022

Motivation

The deadline to switch to Google Analytics 4 is steadily approaching. After poking through this module and a few others (google-gtag-module, gtm-module), it seems like support has dried up. Since this library builds upon the battle-tested approach of vue-analytics, switching to use vue-gtag is the least amount of lift to add support. This support burden is amplified by the recent release of Nuxt 3 and will require some slight tweaks to support the new module architecture.

I think the best course of action is to start by adding gtag support as an opt-in option to this version of the plugin. This way, any consumers who want to bump their analytics scripts without updating Nuxt can do so. After that, the next major version of this plugin can be written to explicitly wrap the vue-gtag API only for Nuxt 3.

I gave these changes a shakedown in local development and the new tag manager appears to be firing out events just fine:
img

Changes:

  • Added a new plugin option useGtag (false by default) that allows users to switch to Google Analytics 4
  • Updated the typings with new optional references to either $ga or $gtag instances and
  • Updated the options typings for Nuxt configs to support vue-gtag options if useGtag is set to true
  • Updated documentation to reflect the valid options when useGtag is set

Relevant (open) issues:

#94
#111
#122
#131
#135

Temporary workarounds for other devs:

I've published a fork containing these exact changes to @abbo/nuxt-google-analytics and I'm currently using that fork in a published project here.

@Abbondanzo Abbondanzo marked this pull request as ready for review December 3, 2022 18:39
@evanrlong
Copy link

Any chance we could get this reviewed and merged? This is an important enhancement, with the UA end-of-life date now less than 4 months away.

Thanks for the work on this @Abbondanzo!

@eugv86
Copy link

eugv86 commented Jun 21, 2023

@pi0 just merge this already, what's the hold up? 🙏😀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants