Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

how to setUserid from user?? #106

Closed
ramHruday opened this issue Apr 17, 2020 · 17 comments
Closed

how to setUserid from user?? #106

ramHruday opened this issue Apr 17, 2020 · 17 comments

Comments

@ramHruday
Copy link

I need to set User on logging in, how can't achieve that..
Any examples

@chrisvanmook
Copy link
Contributor

@ramHruday I'm not sure what you want to do... Could you explain in detail / give an example what do you want to accomplish?

@ramaHruday
Copy link

ramaHruday commented Apr 17, 2020

_paq.push(['setUserId', 'USER_ID_HERE']);
_paq.push(['trackPageView']);

i actually want to set the userid..after he logs in my application

thanks for immediate response

@chrisvanmook
Copy link
Contributor

@ramaHruday Unfortunately it's still too insufficient info... Which package are you using (react or js?) I strongly suggest you take a look at the documentation on how to track events and page views, as we use different methods to call them (unlike your example with _paq):

Hope this helps

@chrisvanmook
Copy link
Contributor

@ramaHruday Is this issue still relevant? Otherwise will close it.

@kris7ian
Copy link

Can this be reopened? I'm looking for this too. More info can be found on matomo's homepage: https://developer.matomo.org/guides/tracking-javascript-guide#user-id

@chrisvanmook
Copy link
Contributor

@chriggi @ramaHruday This is fixed in version v0.1.5

@kris7ian
Copy link

kris7ian commented Jun 7, 2020

@chrisvanmook unfortunately it's not fixed yet. While you can set a userId on initialization, I can't set it programmatically (via _paq.push(['setUserId', 'USER_ID_HERE']);, see my link above). I don't have the userId yet on initialization as it is stored in the redux store, and it might only be available after login.
Ideally we could have a function similar to trackPageView named setUserId which sets the userId after initialization.
Thanks

PS: can this issue be reopened for others to see? I saw someone else opened a similar issue which was closed because of insufficient description.

@chrisvanmook chrisvanmook reopened this Jun 7, 2020
@chrisvanmook
Copy link
Contributor

@chriggi thanks for the clear explanation. I think this is something to take into account when working on issue #176

@CoenWarmer
Copy link

This would be very nice to have :)

@jonkoops
Copy link
Owner

jonkoops commented Aug 3, 2020

This should now be possible on master by calling pushInstruction as follows:

const tracker = new MatomoTracker({ ... })

tracker.pushInstruction('setUserId', 'USER_ID_HERE')

@jonkoops jonkoops closed this as completed Aug 3, 2020
@lgp171188
Copy link
Contributor

lgp171188 commented Aug 30, 2020

@jonkoops, since the fix for this issue is on the master branch and not in a tagged release, can you create a new tagged release so that it is possible to make use of this feature? Thank you!

@jonkoops
Copy link
Owner

@lgp171188 We just released v0.2.0 which includes this change.

@lgp171188
Copy link
Contributor

@jonkoops, this is great news! Thanks for acting and responding very quickly! 👍🏼

@lgp171188
Copy link
Contributor

lgp171188 commented Sep 1, 2020

(this issue is probably not the right place to ask this question, but can't find a better place)

@jonkoops, the usage instructions that you have shared are not clear about how one could use the pushInstruction method from a React component under the MatomoProvider component tree. For instance, the useMatomo function doesn't return the pushInstruction method of the instance here. Should one create an instance manually by

const instance = React.useContext(MatomoContext);

to get the already created instance?

If yes, I'd like to submit a documentation PR mentioning this. If not, would it be okay to expose the pushInstruction method in via the useMatomo function? I can submit a PR for that as well.

@jonkoops
Copy link
Owner

jonkoops commented Sep 2, 2020

@lgp171188 Yeah, I am not happy with how the React context works here. We're thinking about changing this API in the future.

I've created #242 to export the method in the useMatomo hook as well. If you want to open up a PR for documentation that is of course always welcome 👍

@lgp171188
Copy link
Contributor

@jonkoops, thanks for the very quick response and creating+merging #242. I have created a documentation PR #243 mentioning the functions exposed by the useMatomo() hook and also an example for using the pushInstructions() function. 👍🏼

Since this is a monorepo with both the JS and React versions of the library, there is no easy way to install the master branch and hence it will be great if you can tag a new release once all the changes planned for that release are merged and ready. Thanks again! 🙂

@jonkoops
Copy link
Owner

jonkoops commented Sep 4, 2020

Thanks @lgp171188, it's much appreciated. If you want to use that package locally I would recommend building the project locally, buidling it and use yarn link or npm link to link the package to your project.

Regardless of this we will publish a new version that includes this fix soon.

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

No branches or pull requests

7 participants