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

docs(gatsby-plugin-guess-js): Document JWT #15969

Merged
merged 2 commits into from
Aug 15, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/gatsby-plugin-guess-js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ module.exports = {
options: {
// Find the view id in the GA admin in a section labeled "views"
GAViewID: `VIEW_ID`,
// Add JWT token to perform authentication on deployment builds
jwt: GA_JWT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what GA_JWT holds?

For gatsbyjs.org we're doing the following to make it work:

jwt: {
  client_email: process.env.ANALYTICS_SERVICE_ACCOUNT,
  private_key: process.env.ANALYTICS_SERVICE_ACCOUNT_KEY,
},

ENV vars look like:

ANALYTICS_SERVICE_ACCOUNT="<name>@<project>.iam.gserviceaccount.com"
ANALYTICS_SERVICE_ACCOUNT_KEY="-----BEGIN PRIVATE KEY-----\nPRIVATE KEY STRING\n-----END PRIVATE KEY-----"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good point, tried to follow the rabbit hole into Guess webpack and ga packages but haven't been able to work out where this goes yet. I can see that client_email, private_key combo in www/ but it appears to be commented out currently?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a bug with guess so that's why :)

minimumThreshold: 0.03,
// The "period" for fetching analytic data.
period: {
Expand All @@ -47,3 +49,15 @@ module.exports = {
],
}
```

### Local development

Using the plugin locally you'll need to authenticate the plugin with GA to gain access to your data. When building you'll be required to sign in to the organisation you'll be feeding the data from.

### Production

If deploying with a service such as netlify or heroku etc, you wont be able to grant access via Google Sign On. To get around this you'll need to generate a JWT for your GA account to pass to the plugin, this will enable the plugin to work in prod without any human interaction to authenticate permissions.

## How to get a JWT token?

[Here](https://2ality.com/2015/10/google-analytics-api.html)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we should just copy and modify https://2ality.com/2015/10/google-analytics-api.html#unlocking-the-google-analytics-api in the readme and give credits to 2ality url.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another good point, I would probably be welcome to more suggestions as to how to do this in a simpler way (if possible?).

Maybe attaching something to a gatsby preBuild api to get a fresh JWT. My knowledge on JWT is a little limited but I would assume that this wouldn't be the best way as each JWT is valid until you make it non valid correct?