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 default pageview "props" to the tracker #19

Open
mouhannad-sh opened this issue Nov 10, 2021 · 1 comment
Open

set default pageview "props" to the tracker #19

mouhannad-sh opened this issue Nov 10, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@mouhannad-sh
Copy link

It would be nice if we can set default props (context) to be sent with every pageview event. So that we can use enableAutoPageviews()

Detailed Description

Right now we can only send custom props with pageviews events using the trackPageview() function.
As a customer who's a multi-tenancy platform provider, I benefit from the simple implementation of the tracker by using enableAutoPageviews(), but if we want to set custom props (e.g. subscription-plan) we'll need to opt-out from using enableAutoPageviews and write our own logic to track every pageview with the desired props

Possible Implementation

I can think of 2 implementations that might work here

1- Allow EventOptions to be passed to enableAutoPageviews

While this might be the simplest to implement, I'm not a big fan of this approach as it would make updating the eventOptions a bit challenging.

PlausibleInstance.enableAutoPageviews(eventOptions?: EventOptions)

2- Add a pageviewProps option to Plausible definition and setPageviewProps to the plausible instance

I'm in favor with this approach as it's easy to use and can be introduced without any breaking changes

const tracker = Plausible({
  domain: "plausible.io",
  pageviewProps: { isLoggedIn: "No" }
});

// auto track pageviews
tracker.enableAutoPageviews()

// and then to update it when needed
tracker.setPageviewProps({ subscriptionPlan: "Enterprise", isLoggedIn: "Yes", ...others })

I'm happy to open a PR with either approaches if needed

@Barbapapazes
Copy link

Hello,

Since this package have not been update for two years, I made a fork.

I rewrite the tracker to be more modular and I fix this issue.

https://github.com/Barbapapazes/plausible-tracker

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

No branches or pull requests

2 participants