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.

How to set a dimension before the first router pageview?

See original GitHub issue

Hello, First of all, a big thanks for this plugin which made it easier for us to set up Google Analytics in our Vue project.

I’m using vue-gtag 1.16.1 with vue 2.6.14.

I’m trying to set a dimension (the value is retrieved from the backend) for all queries made to Google Analytics. But I can’t do: ["set", {dimension1: "MY_VALUE"}] before the first: ["event", "page_view", {page_title: "MY_TITLE", page_path: "/", page_location: "http://localhost:4200/", send_page_view: true}]

I do not perform the pageview manually, they are triggered by the router. The first pageview does not contain the dimension, the following ones do.

I have tried a lot of things without success, for example:

  • bootstrap: false, then set(dimension), then bootstrap()
  • enabled: false, then set(dimension), then this.$gtag.optIn()

Here is the sample code from my last try:

Vue.use(VueGtag,
    {
      config: {id: 'UA-XXX'},
      bootstrap: true,
      enabled: false,
    },
    router,
);
   created(): void {
      userService.getCurrentUser().then((user) => {

        this.$gtag.set({
          dimension1: user.role,
        });

        this.$gtag.optIn();
      });
    }

Output with the Google Analytics Debugger:

Processing GTAG command: [“event”, “page_view”, {page_title: “MY_TITLE”, page_path: “/”, page_location: “http://localhost:4200/”, send_page_view: true}] Processing GTAG command: [“set”, {dimension1: “MY_VALUE”}]

Thanks in advance for the help 🙏🏻

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
MatteoGabrielecommented, Jun 23, 2021

Yeah I’m currently supporting both at the moment. We’ll see in the future

0reactions
ebrakecommented, May 31, 2022

+1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom dimensions & metrics - Analytics Help - Google Support
Before you can send custom dimension and metric values to Analytics, they must first be defined in an Analytics property. Each Analytics property...
Read more >
The Beginners Guide to Custom Dimensions in Google Analytics
Navigate to Insights » Settings from your dashboard and click on the Conversions tab. ... Scroll down to the Custom Dimensions section and...
Read more >
How to create Custom Dimension & get Unique PageView ...
But for the custom dimension creation, below is the answer: ... your event parameters before mapping them over to the custom dimensions on ......
Read more >
Set up Custom Dimensions using GA, GTM, and the Data Layer
In GTM, find the tag you want to attach the dimensions to. Usually this will be the GA page view tag, but other...
Read more >
Google Analytics Timestamp Custom Dimension ... - YouTube
Do you need to determine exactly when a pageview, event, transaction or other GA hit happened? Then check out this video where we...
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