MatteoGabriele / vue-gtag

Global Site Tag plugin for Vue (gtag.js)
https://matteo-gabriele.gitbook.io/vue-gtag/
MIT License
867 stars 67 forks source link

Question: Custom Fields #59

Closed tstrumfels closed 4 years ago

tstrumfels commented 4 years ago

I had previously used your vue-analytics library, and I saw that you recommended vue-gtag going forward.

We have a custom field for userId in our Google Analytics. Below was the usage to tell vue-analytics about it.

In this case, looking to accomplish the same thing with vue-gtag - to pass in the userID field from my app into the vue-gtag library.

Thanks!

Vue.use(VueAnalytics, { id: "GAID", fields: { userId: "user123", }, set: [

  { field: 'user_id', value: "user123" },

], router,

debug: { enabled: false, // default value trace: false, // default value sendHitTask: true, // default value }, });

MatteoGabriele commented 4 years ago

you can achieve it by passing the params object in your configuration

Vue.use(VueGtag, { 
  config: {
    id: 'GA_MEASUREMENT_ID',
    params: { 
      'user_id': 'user123'
    }
  }
})

https://matteo-gabriele.gitbook.io/vue-gtag/#initial-config-parameters

tstrumfels commented 4 years ago

Thanks Matteo! (good work on this, by the way!)

I will give this a go, although was able to achieve a different way as well.

Appreciate the timely response.

From: Matteo Gabriele notifications@github.com Sent: Monday, January 27, 2020 3:33 AM To: MatteoGabriele/vue-gtag vue-gtag@noreply.github.com Cc: Strumfels, Timothy Timothy.Strumfels@arcadis.com; Author author@noreply.github.com Subject: Re: [MatteoGabriele/vue-gtag] Question: Custom Fields (#59)

Closed #59https://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMatteoGabriele%2Fvue-gtag%2Fissues%2F59&data=02%7C01%7CTimothy.Strumfels%40arcadis.com%7C7ea5850398d7406133a308d7a30391e9%7C7f90057d3ea046feb07ce0568627081b%7C1%7C0%7C637157108044326537&sdata=O5aUT88Z8IYoUxcxlGvi9Mu3Rt9gKGNvSXqeZYfb5gw%3D&reserved=0.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2FMatteoGabriele%2Fvue-gtag%2Fissues%2F59%3Femail_source%3Dnotifications%26email_token%3DABMHMWD2UKH3QXX4EKQI22TQ72L5FA5CNFSM4KLKEGL2YY3PNVWWK3TUL52HS4DFWZEXG43VMVCXMZLOORHG65DJMZUWGYLUNFXW5KTDN5WW2ZLOORPWSZGOWGWMOSY%23event-2980890443&data=02%7C01%7CTimothy.Strumfels%40arcadis.com%7C7ea5850398d7406133a308d7a30391e9%7C7f90057d3ea046feb07ce0568627081b%7C1%7C0%7C637157108044336495&sdata=QVixieQO9iVVBdnRpoVjgZJshd%2B2JTJZ7gcQ7lPmDig%3D&reserved=0, or unsubscribehttps://nam02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FABMHMWDAR5SFROSSD4GT75TQ72L5FANCNFSM4KLKEGLQ&data=02%7C01%7CTimothy.Strumfels%40arcadis.com%7C7ea5850398d7406133a308d7a30391e9%7C7f90057d3ea046feb07ce0568627081b%7C1%7C0%7C637157108044336495&sdata=WL9yVNQgD7Yd2UepUTz9lGvXOQpN44mAWxyU%2F9SlABM%3D&reserved=0.

This email and any files transmitted with it are the property of Arcadis and its affiliates. All rights, including without limitation copyright, are reserved. This email contains information that may be confidential and may also be privileged. It is for the exclusive use of the intended recipient(s). If you are not an intended recipient, please note that any form of distribution, copying or use of this communication or the information in it is strictly prohibited and may be unlawful. If you have received this communication in error, please return it to the sender and then delete the email and destroy any copies of it. While reasonable precautions have been taken to ensure that no software or viruses are present in our emails, we cannot guarantee that this email or any attachment is virus free or has not been intercepted or changed. Any opinions or other information in this email that do not relate to the official business of Arcadis are neither given nor endorsed by it.

sneko commented 4 years ago

Hi @MatteoGabriele ,

Thanks for your answer. I'm wondering what would you recommend since the user can log in and log out (the user ID will change).

I know there is the setOptions() I could use, but how to re-init the complete GTag flow?

Thank you,

EDIT: ok it seems according to Google and also previous issues on vue-analytics the best way is to use set():

this.$gtag.set({'userId': 'USER_ID'}); // Set the user ID using signed-in user_id.

Sorry for disturbing. It may help in the set() doc page to talk about this example.