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

Add enableTracking function and allow lazy loading #736

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

opsidao
Copy link

@opsidao opsidao commented Jan 19, 2022

As a solution to #478 here a propose adding a enableTracking function to MatomoTracker which does the loading of the matomo.js file and the emission of the correct events. This function is just an extraction of the last part of the initializer on the MatomoTracker that is exposed through the useMatomo hook, allowing users to delay loading the actual matomo library by:

  • Passing disabled when creating the Matomo instance, which skips loading the scripts
  • Extracting the enableTracking function from the object returned by useMatomo and call it when they know that users have given consent for tracking.

A simplified usage example is included in the README file.


Before opening a pull request, please ensure:

Be kind to code reviewers, please try to keep pull requests as small and focused as possible :)

@opsidao
Copy link
Author

opsidao commented Jan 31, 2022

No opinions here?

@opsidao
Copy link
Author

opsidao commented Mar 10, 2022

anyone there

@jonkoops jonkoops requested review from thomasm0 and alimpens May 4, 2022 09:23
@jonkoops
Copy link
Owner

jonkoops commented May 4, 2022

Sorry for the lack of replies, I am currently swamped with a lot of other work so I do not have time to review these changes.

Copy link
Contributor

@timvanoostrom timvanoostrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you just dely the instantiation of the tracker?

let matomoTracker = null;

function track(payload: any) {
  matomoTracker?.trackPageView(payload);
}

function Component() {
  const isEnabled = useState(false);

  useEffect(() => {
    if (isEnabled) {
      matomoTracker = new MatomoTracker({ ... });
    }
  }, [isEnabled]);

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

Successfully merging this pull request may close these issues.

None yet

3 participants