How to set a dimension before the first router pageview?
See original GitHub issueHello, 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, thenset(dimension), thenbootstrap()…enabled: false, thenset(dimension), thenthis.$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:
- Created 2 years ago
- Comments:7 (2 by maintainers)

Top Related StackOverflow Question
Yeah I’m currently supporting both at the moment. We’ll see in the future
+1