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

Add possibility to provide a custom tracker class #78

Open
christophercr opened this issue Dec 15, 2023 · 1 comment
Open

Add possibility to provide a custom tracker class #78

christophercr opened this issue Dec 15, 2023 · 1 comment

Comments

@christophercr
Copy link

christophercr commented Dec 15, 2023

First of all thanks a lot for such a useful lib! Works like a charm! 👏

I would like to use the Matomo Tag Manager and I also need to "push" other data into the _mtm variable. Perfhaps this is out of the scope of ngx-matomo and maybe what I'm going to explain below is not feasible, but who knows 😛

Currently there is no way to perform custom logic nor pushing custom data into the _mtm variable because there are only 2 trackers to use in the library: NoopMatomoTracker and StandardMatomoTracker. The latter as its name suggests, works out of the box with a standard Motomo traking workflow and uses the _paq variable.

image

I think this could be enhanced by being able to provide a custom Matomo tracker class, via the config for example, so that such class can be instantiated instead of the Noop or Standard ones.

export function createMatomoTracker(
  config: InternalMatomoConfiguration,
  platformId: Object,
  ngZone: NgZone,
): MatomoTracker {
  if (config.disabled || !isPlatformBrowser(platformId)) {
     return new NoopMatomoTracker();
  }

  return config.customTrackerClass;
    ? new config.customTrackerClass(ngZone, config)
    : new StandardMatomoTracker(ngZone, config);
}

From then on, everything should be fairly simple for the developer since the tracker class should extend the MatomoTracker abstract class as the other 2 trackers. This way any custom logic could be placed in the push() for example or in any trackXXXX() method if needed.

Not really sure if this would fit in ngx-matomo in its current state cause what I actually need is to customize data to be sent to the Tag Manager and trigger some other logic in my own app whenever such events are sent.

What do yo think?

@EmmanuelRoux
Copy link
Owner

Hi @christophercr
Thank you for your message and the suggestion!

Actually this library was not originally designed to work specifically with Tag Manager, but I think it would be a great idea to provide better integration indeed!

Your suggestion seems good. I would just suggest to use dependency injection instead of instantiate a class directly.

Feel free to open a PR so we can work on it!

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

No branches or pull requests

2 participants