@lapwy/js 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,20 @@
1
- # Temporary Holding Version
1
+ # @lapwy/js
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The lapwy tracker for any website or single-page app.
4
+
5
+ ```sh
6
+ npm install @lapwy/js
7
+ ```
8
+
9
+ ```js
10
+ import { init, track } from "@lapwy/js";
11
+
12
+ init({ site: "lw_…" }); // once, in the browser
13
+ track("signup", { plan: "pro" }); // anywhere, any time
14
+ ```
15
+
16
+ Route changes are followed on their own. `init` is safe to call more than once and safe on a server, where it does nothing. Calls made before `init` are kept and sent after it.
17
+
18
+ Also exported: `page`, `consent` and `notFound`.
19
+
20
+ With React, Next.js or Vue, use [`@lapwy/react`](https://www.npmjs.com/package/@lapwy/react), [`@lapwy/next`](https://www.npmjs.com/package/@lapwy/next) or [`@lapwy/vue`](https://www.npmjs.com/package/@lapwy/vue) instead of calling `init` yourself.
@@ -0,0 +1,55 @@
1
+ export type Props = Record<string, string | number | boolean>;
2
+ export type Options = {
3
+ /** The site's public key, from its Install screen. */
4
+ site: string;
5
+ /** Where events go. Defaults to lapwy's own ingest. */
6
+ endpoint?: string;
7
+ /**
8
+ * "always": keep a first-party id. "consent": only after consent(true).
9
+ * Anything else: never. The site's setting in lapwy must ask for it too.
10
+ */
11
+ cookie?: "always" | "consent" | false | null;
12
+ /** Your build or version, to see what a release changed. */
13
+ release?: string;
14
+ /**
15
+ * Calls the page makes with fetch and XMLHttpRequest are counted per
16
+ * endpoint: how many, how many failed, how long they took. Calls to the
17
+ * page's own domain always count; list other API hosts here
18
+ * (["api.example.com"]). false switches it off.
19
+ */
20
+ api?: string[] | false;
21
+ /**
22
+ * Pages to count as one. By default every address is its own page. A
23
+ * pattern groups the ones that differ only by an id or a name:
24
+ * ["/blog/:slug", "/users/:id/orders/:order", "/docs/*"]. A part that
25
+ * starts with ":" stands for any one part of the path; "*" at the end
26
+ * stands for everything after it. A page that fits is sent as the pattern
27
+ * itself, so the id never leaves the browser, and the pages cannot be told
28
+ * apart afterwards. The first pattern that fits wins.
29
+ */
30
+ pages?: string[];
31
+ /**
32
+ * Full control over the path that is sent, for what patterns cannot say:
33
+ * path: (p) => p.replace(/^\/(en|nl|de)\//, "/"). Used instead of pages.
34
+ */
35
+ path?: (path: string) => string;
36
+ /** Names the sender in the data. Set by the entry points. */
37
+ sdk?: string;
38
+ };
39
+ export type Tracker = {
40
+ /** Something a visitor did: track("signup", { plan: "pro" }). */
41
+ track: (name: string, props?: Props) => void;
42
+ /** A page view. Called on its own for the first page and for every route change. */
43
+ page: (props?: Props) => void;
44
+ /** Tell the tracker what the visitor said about cookies. Only matters with cookie: "consent". */
45
+ consent: (granted: boolean) => void;
46
+ /**
47
+ * This page is a dead end: call it from the "not found" screen of a
48
+ * single-page app, which the browser cannot tell from a real page.
49
+ * A page the server answers with a 404 or a 500 is seen without it.
50
+ */
51
+ notFound: (status?: number) => void;
52
+ };
53
+ export declare const DEFAULT_ENDPOINT = "https://in.lapwy.com/e";
54
+ /** Starts tracking this page. Call it once, in the browser. On a server it does nothing. */
55
+ export declare function start(options: Options): Tracker;
package/dist/core.d.ts ADDED
@@ -0,0 +1,55 @@
1
+ export type Props = Record<string, string | number | boolean>;
2
+ export type Options = {
3
+ /** The site's public key, from its Install screen. */
4
+ site: string;
5
+ /** Where events go. Defaults to lapwy's own ingest. */
6
+ endpoint?: string;
7
+ /**
8
+ * "always": keep a first-party id. "consent": only after consent(true).
9
+ * Anything else: never. The site's setting in lapwy must ask for it too.
10
+ */
11
+ cookie?: "always" | "consent" | false | null;
12
+ /** Your build or version, to see what a release changed. */
13
+ release?: string;
14
+ /**
15
+ * Calls the page makes with fetch and XMLHttpRequest are counted per
16
+ * endpoint: how many, how many failed, how long they took. Calls to the
17
+ * page's own domain always count; list other API hosts here
18
+ * (["api.example.com"]). false switches it off.
19
+ */
20
+ api?: string[] | false;
21
+ /**
22
+ * Pages to count as one. By default every address is its own page. A
23
+ * pattern groups the ones that differ only by an id or a name:
24
+ * ["/blog/:slug", "/users/:id/orders/:order", "/docs/*"]. A part that
25
+ * starts with ":" stands for any one part of the path; "*" at the end
26
+ * stands for everything after it. A page that fits is sent as the pattern
27
+ * itself, so the id never leaves the browser, and the pages cannot be told
28
+ * apart afterwards. The first pattern that fits wins.
29
+ */
30
+ pages?: string[];
31
+ /**
32
+ * Full control over the path that is sent, for what patterns cannot say:
33
+ * path: (p) => p.replace(/^\/(en|nl|de)\//, "/"). Used instead of pages.
34
+ */
35
+ path?: (path: string) => string;
36
+ /** Names the sender in the data. Set by the entry points. */
37
+ sdk?: string;
38
+ };
39
+ export type Tracker = {
40
+ /** Something a visitor did: track("signup", { plan: "pro" }). */
41
+ track: (name: string, props?: Props) => void;
42
+ /** A page view. Called on its own for the first page and for every route change. */
43
+ page: (props?: Props) => void;
44
+ /** Tell the tracker what the visitor said about cookies. Only matters with cookie: "consent". */
45
+ consent: (granted: boolean) => void;
46
+ /**
47
+ * This page is a dead end: call it from the "not found" screen of a
48
+ * single-page app, which the browser cannot tell from a real page.
49
+ * A page the server answers with a 404 or a 500 is seen without it.
50
+ */
51
+ notFound: (status?: number) => void;
52
+ };
53
+ export declare const DEFAULT_ENDPOINT = "https://in.lapwy.com/e";
54
+ /** Starts tracking this page. Call it once, in the browser. On a server it does nothing. */
55
+ export declare function start(options: Options): Tracker;