plausible / plausible-tracker

Frontend library to interact with Plausible Analytics
https://github.com/plausible/plausible-tracker
MIT License
214 stars 46 forks source link

Create Interface for Plausible instance #50

Open alejandrocoding opened 1 year ago

alejandrocoding commented 1 year ago

Detailed Description

When creating an instance of Plausible, Typescript infer the typing, but there is not an explicit interface to import to use in our TS apps.

Context

When using this library in a class, like in Angular Services, you might want to declare the class property, give it a type and in the constructor or in the init() method of your class, you might want to create the instance. Because there is no interface, you might be forced to declare the property as any, which will make your instance untyped.

Possible Implementation

Extracting the type into an interface or type will allow devs to have an explicit type for the instance to get benefit of the strict typed system.

https://github.com/plausible/plausible-tracker/blob/master/src/lib/tracker.ts#L212-L217

It should be really easy to do and will be a great benefit, imo. I can help with a PR if this FR makes sense.

sandstrom commented 1 year ago

Somewhat related, it would also make sense to make a clear distinction between the tracker client, and the wrapper.

https://github.com/plausible/analytics/discussions/2414