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

Add support for Google Optimize within the Google Analytics plugin #8099

Closed
jonhorton opened this issue Sep 12, 2018 · 2 comments
Closed

Add support for Google Optimize within the Google Analytics plugin #8099

jonhorton opened this issue Sep 12, 2018 · 2 comments
Labels
good first issue Issue that doesn't require previous experience with Gatsby help wanted Issue with a clear description that the community can help with.

Comments

@jonhorton
Copy link
Contributor

Summary

Within the Google Analytics Plugin, there isn't currently a way to specific a Google Optimize container id to allow for easy A/B testing.

Basic example

Here's a link to the Google Optimize recommended setup: https://support.google.com/optimize/answer/6262084?hl=en

This method basically boils down to adding ga('require', 'GTM-XXXXXX'); where GTM-XXXXXX is the container id. Here's an example of where this line is added:

    ga('create', 'UA-XXXXXXXX-X', 'auto');
    ga('require', 'GTM-XXXXXX');
    ga('send', 'pageview');

It seems that this could easily be added to the existing google analytics plugin, following the anonymize line:

+ (typeof pluginOptions.anonymize !== "undefined" ? "ga('set', 'anonymizeIp', 1);" : "") + "\n "     
+ (typeof pluginOptions.optimizeId !== "undefined" ? "ga('require', " + pluginOptions.optimizeId + ");" : "") + "}\n "

And would allow for setting this Id in gatsby-config:

options: {
        trackingId: "YOUR_GOOGLE_ANALYTICS_TRACKING_ID",
        // Puts tracking script in the head instead of the body
        head: false,
        // Setting this parameter is optional
        anonymize: true,
        // Setting this parameter is also optional
        respectDNT: true,
        // Avoids sending pageview hits from custom paths
        exclude: ["/preview/**", "/do-not-track/me/too/"],
        optimizeId: "YOUR_GOOGLE_OPTIMIZE_TRACKING_ID",
        // Enables Google Optimize using your Id
      },

Motivation

Adding support for a Google Optimize Id builds on the already existing support for Google Analytics + Google Tag Manager and makes it very simple for users to easily perform complex A/B + multivariate tests on their existing Gatsby sites.

Would be happy to submit a PR with this addition and welcome any feedback beforehand!

@kakadiadarpan
Copy link
Contributor

kakadiadarpan commented Sep 13, 2018

We'd love to have your help, @jonhorton! Please feel free to submit a PR since you already know what changes to make. This is where you will need to make the changes.

@kakadiadarpan kakadiadarpan added help wanted Issue with a clear description that the community can help with. good first issue Issue that doesn't require previous experience with Gatsby labels Sep 13, 2018
@jonhorton
Copy link
Contributor Author

Thanks @kakadiadarpan!

Closing this issue as the PR that adds this functionality has been successfully merged 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Issue that doesn't require previous experience with Gatsby help wanted Issue with a clear description that the community can help with.
Projects
None yet
Development

No branches or pull requests

3 participants