question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[gatsby-plugin-google-analytics] Need custom definition usage (custom dimensions and metrics)

See original GitHub issue

Summary

The gatsby-plugin-google-analytics plugin works well but lacks information on how to set custom dimensions (or other fields) prior to the pageview hit being sent. Some data can be set in gatsby-config but this doesn’t work for anything dynamic.

Relevant information

For example, I need to retrieve a GET parameter value and set it as a custom dimension before the pageview hit is sent so that all subsequent hits (including pageview) will include this information.

For example, take the following URL: https://howchoo.com/h/pi?ref=interest_list

Before the GA pageview it is sent, I would normally set it here:

ga('set', 'dimension5', 'custom data');

I could theoretically retrieve the value in gatsby-browser and set it there, but GA doesn’t provide a true async queue before the ga object is defined AFAIK. Therefore, I’d need to be sure it gets set before the plugin sends the pageview hit.

How could this be done? The plugin isn’t clear about how custom definitions (dimensions and metrics) can be set before the pageview hit is sent. This seems to be a relevant section of code.

Environment (if relevant)

  System:
    OS: macOS 10.15.3
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.8.0 - /usr/local/bin/node
    npm: 6.10.3 - /usr/local/bin/npm
  Languages:
    Python: 2.7.16 - /usr/bin/python
  Browsers:
    Chrome: 80.0.3987.149
    Firefox: 71.0
    Safari: 13.0.5
  npmPackages:
    gatsby: ^2.19.45 => 2.19.45
    gatsby-plugin-disqus: ^1.1.4 => 1.1.4
    gatsby-plugin-google-analytics: ^2.1.38 => 2.1.38
    gatsby-plugin-google-tagmanager: ^2.1.27 => 2.1.27
    gatsby-plugin-less: ^3.0.21 => 3.0.21
    gatsby-plugin-lodash: ^3.1.22 => 3.1.22
    gatsby-plugin-manifest: ^2.2.48 => 2.2.48
    gatsby-plugin-mdx: ^1.0.83 => 1.0.83
    gatsby-plugin-offline: ^3.0.41 => 3.0.41
    gatsby-plugin-react-helmet: ^3.1.24 => 3.1.24
    gatsby-plugin-react-svg: ^3.0.0 => 3.0.0
    gatsby-plugin-remove-trailing-slashes: ^2.1.24 => 2.1.24
    gatsby-plugin-sass: ^2.1.31 => 2.1.31
    gatsby-plugin-webpack-bundle-analyzer: ^1.0.5 => 1.0.5
    gatsby-source-filesystem: ^2.1.56 => 2.1.56
    gatsby-source-graphql: ^2.1.35 => 2.1.35
    gatsby-source-shopify: ^3.0.52 => 3.0.52
    gatsby-source-youtube: ^1.0.1 => 1.0.1
    gatsby-transformer-yaml: ^2.2.27 => 2.2.27
  npmGlobalPackages:
    gatsby-cli: 2.10.2

File contents (if changed)

gatsby-config.js: N/A package.json: N/A gatsby-node.js: N/A gatsby-browser.js: N/A gatsby-ssr.js: N/A

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
noah-hornakcommented, May 11, 2020

Would also like to know how to accomplish this. Trying to send custom dimension on page view event for a specific page so I can A/B test.

0reactions
github-actions[bot]commented, Jul 5, 2020

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community! 💪💜

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom dimensions & metrics - Analytics Help - Google Support
Overview. Custom dimensions and metrics allow you to combine Analytics data with non-Analytics data, e.g. CRM data. For example:.
Read more >
How to Set Custom Dimensions and Metrics in ... - Ken Williams
In this post we will discuss how custom definitions have changed, explain what you need to know before migrating them from Universal Analytics, ......
Read more >
Google Analytics Tutorial - Custom dimensions and metrics
Learn how to configure custom dimensions and metrics in GA4 and how they can be useful. Explore more Google Analytics courses and advance ......
Read more >
How To Set Custom Dimensions And ... - Search Discovery
Learn how custom definitions (AKA custom dimensions and metrics) have changed in Google Analytics 4 (GA4) & what you need to know before ......
Read more >
The Beginners Guide to Custom Dimensions in Google Analytics
In this article, we'll explain everything you need to know about Google Analytics custom dimensions, and how to use them for your WordPress ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found