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

Use functions for getting information #180

Open
veermetri05 opened this issue Jul 8, 2020 · 2 comments
Open

Use functions for getting information #180

veermetri05 opened this issue Jul 8, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@veermetri05
Copy link

veermetri05 commented Jul 8, 2020

Is your feature request related to a problem? Please describe.
A Yes I want to fetch user's visitorId . It is not possible every visitor on my website is logged in. If the user is logged in then I am able to set the userId on initialization. But I want to get the visitorId of the current user. This can be achieved by passing a function as described in the documentation.

var visitor_id;
_paq.push([ function() { visitor_id = this.getVisitorId(); }]); 

But I didn't find a way to do that with the @datapunk/matomo-tracker-react

So I am requesting a feature to add passing functions to the Configuration of the Tracker Object (as mentioned on the documentation)

Describe the solution you'd like
A Be able to pass functions or getting visitorId directly

Describe alternatives you've considered
A I found out this plugin. I haven't tried any alternative methods that have found information here.

Additional context
I haven't worked with the javascript tracker by matomo I thought this plugin has all features.
I want to fetch the visitorId to track the user's behavior (page he visits, time spent on the website, etc). Then based on the data we will recommend articles that the user will like to read.

Resources
https://developer.matomo.org/api-reference/tracking-javascript
https://developer.matomo.org/guides/tracking-javascript-guide

Package Used
https://github.com/Amsterdam/matomo-tracker/tree/master/packages/react

@jonkoops jonkoops self-assigned this Aug 3, 2020
@jonkoops jonkoops added enhancement New feature or request help wanted Extra attention is needed labels Aug 3, 2020
@jonkoops jonkoops added this to the 0.2.0 milestone Aug 3, 2020
@jonkoops
Copy link
Owner

jonkoops commented Aug 3, 2020

Hi @veermetri05, this is certainly something we would want to include in a newer version. I am adding this to our backlog.

@jonkoops jonkoops removed this from the 0.2.0 milestone Aug 31, 2020
@jonkoops jonkoops added the good first issue Good for newcomers label Sep 1, 2020
@jonkoops jonkoops added this to the 0.2.1 milestone Sep 1, 2020
@jonkoops jonkoops modified the milestones: 0.2.1, 0.3.0 Sep 10, 2020
@jutunen
Copy link

jutunen commented Oct 31, 2022

It is quite straightforward to expand the hook to get broader tracking API support.

For example, here is how to add hasRememberedConsent feature to the hook.

Just add following function to useMatomo.js:

const hasRememberedConsent = useCallback(() => {
        let rval;
        // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
        instance === null || instance === void 0 ? void 0 : instance.pushInstruction(function() { rval = this.hasRememberedConsent(); });
        return rval;
    }, [instance]);

    return {
        trackEvent,
        trackEvents,
        trackPageView,
        trackSiteSearch,
        trackLink,
        enableLinkTracking,
        pushInstruction,
        hasRememberedConsent
    };

Also remember to add the new function to the returned object.

How to use the new function in React client:

const { trackPageView, hasRememberedConsent } = useMatomo();

if( hasRememberedConsent() === false ) console.log("...");

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants