plausible-tracker icon indicating copy to clipboard operation
plausible-tracker copied to clipboard

Create Interface for Plausible instance

Open alejandrocoding opened this issue 3 years ago • 1 comments

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.

alejandrocoding avatar Nov 15 '22 15:11 alejandrocoding

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

sandstrom avatar Nov 30 '22 12:11 sandstrom