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 Google Global Site Tag Plugin #8341

Closed
tylerthebuildor opened this issue Sep 19, 2018 · 8 comments · Fixed by #9032
Closed

Add Google Global Site Tag Plugin #8341

tylerthebuildor opened this issue Sep 19, 2018 · 8 comments · Fixed by #9032
Labels
help wanted Issue with a clear description that the community can help with.

Comments

@tylerthebuildor
Copy link
Contributor

Prerequisite

The way I understand it is that Google now has 3 properties for tracking visitors on a website. These 3 are similarly named and sort of do the same thing so I want to define them up front so no one gets confused.

  1. Google Analytics/GA/analytics.js - This is the legacy code snippet that is used to send data to Google Universal Analytics

  2. Global Site Tag/GST/gtag.js - This is the new code snippet that is also used to send data to Google Universal Analytics. It is an improved library taking into consideration modern standards and it has the added benefit of integrating with other Google Services such as Adwords.

  3. Google Tag Manager or GTM - This is different from the other two in that once it is enabled on a site the events can be updated via the GTM dashboard and doesn't require a developer. This is a cool technology but isn't what I'll be talking about today.

There are already Gatsby plugins for 1 and 3 but not for 2.

https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-google-analytics
https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-google-tagmanager

Proposal

Given the fact that more of Google's services are converging on the gtag.js snippet I think it makes sense to add an official Gatsby plugin packages/gatsby-plugin-google-gtag.

Is this something the community has already been thinking about or something we'd be interested in adding?

Resources

@KyleAMathews
Copy link
Contributor

Seems like a great plan! Would love an official plugin added here for it.

@kakadiadarpan
Copy link
Contributor

@tylerbuchea would you like to create this plugin for Gatsby?

@kakadiadarpan kakadiadarpan added help wanted Issue with a clear description that the community can help with. type: feature or enhancement labels Sep 20, 2018
@tylerthebuildor
Copy link
Contributor Author

It'd be an honor 🙂

@kmjennison
Copy link

I wrote a quick version of this here, in case it helps:

// gatsby-ssr.js
import React from 'react'
import { oneLine } from 'common-tags'

exports.onRenderBody = ({ setHeadComponents }) => {
  const GST_ID = 'SOME_ID'
  if (process.env.NODE_ENV === `production`) {
    setHeadComponents([
      <script
        key="google-gst-js"
        async
        src={`https://www.googletagmanager.com/gtag/js?id=${GST_ID}`}
      />,
      <script
        key="google-gst-init"
        dangerouslySetInnerHTML={{
          __html: oneLine`
            window.dataLayer = window.dataLayer || [];
            function gtag(){dataLayer.push(arguments);}
            gtag('js', new Date());
            gtag('config', '${GST_ID}');`,
        }}
      />,
    ])
  }
}

Happy to publish a plugin, too, though it'll be a week or two before I get around to it.

@tylerthebuildor
Copy link
Contributor Author

Yeah kmjennison that is essentially it. There are some other pieces revolving around gtag options, multiple trackingIds, DNT, and pageview events. I'm done building the plugin and in the testing phase with my brother now. Would love some help though if you're interested?

@kmjennison
Copy link

@tylerbuchea Sure, happy to help, though mostly offline this week. LMK how I can be helpful.

@AmilKey
Copy link

AmilKey commented Oct 9, 2018

@tylerbuchea any updates here?

@tylerthebuildor
Copy link
Contributor Author

Been busy moving but my goal is to open the PR before this weekend.

DSchau pushed a commit that referenced this issue Oct 16, 2018
This PR adds support for Google's Global Site Tag (gtag) and closes #8341 you can view that issue for a detailed breakdown.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Issue with a clear description that the community can help with.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants