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

Set user Id and custom dimension after plugin instantiation #22

Open
KevinStong opened this issue May 2, 2017 · 4 comments
Open

Set user Id and custom dimension after plugin instantiation #22

KevinStong opened this issue May 2, 2017 · 4 comments
Labels

Comments

@KevinStong
Copy link

Hi Everyone,

Was curious on what the community insight/feedback would be around setting data with the plugin after instantiation in main or after lazy initialization of the plugin in the page lifecycle of a module?

I was looking to pass a custom dimension for the user's role on our site in addition to the userId variable to track users across devices. The problem is that I dont get this data until the user is logged in which occurs in app.js after the events in main.js which has the Framework configuration for loading the plugin. Now, I could easily do the following:

ga('set', 'userId', '11111')

in the activate of the app.js module but I was looking for a way to keep the google analytics concerns internal to the plugin.

Another thought on this was to lazy load the plugin in the app.js activation using the FrameworkConfiguration class from aurelia-framwork:

activate() {
  return new FrameworkConfiguration(this.aurelia).plugin('aurelia-google-analytics').apply();
}

then pass in the variables via init() as these params can also be included on the ga('create') initialization call but I was concerned about having this plugin instantiated outside of main.js where I am doing the remainder of the work setting up other plugins. I also didn't really like this sprinkled about in the application requiring someone to have to go looking for it.

thoughts on this? Curious on how others are handing this as well...

thanks!

Kevin

@miguelzakharia
Copy link
Owner

Hi Kevin,

I came across the exact scenario you bring up and went through the same thought process as you. I ended up just using ga('set', 'userId', '11111'). I couldn't find a better way to do it at the time. I also considered creating a function on the plugin that can be called to set the user after initialization. It would basically just be a wrapper around the ga('set'...). It would hide the internals, but is not providing much benefit other than encapsulation. I felt that it might lead to a slippery slope of wrapping all of the features of GA in this manner which I think is not very elegant.

I'm certainly open to suggestions and collaborating on a better abstraction.

@LukevanTricht
Copy link

This would be really nice, especially for those of us using Typescript, as we can't call the ga object because it's not declared anywhere, and thus the Typescript compiler complains and refuses. So either a method which exposes ga, or methods which give us more access to the ga object would be fantastic.

@dantheother
Copy link

@LukevanTricht
Copy link

@LukevanTricht does https://www.npmjs.com/package/@types/google.analytics help?

I can imagine that would do exactly what I wanted, but unfortunately I no longer work for the company I was building that software for, so I have no way of testing at this time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants