@analytix/tracker 0.3.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/dist/index.d.ts +20 -0
- package/dist/index.js +45 -0
- package/package.json +35 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createAnalytixClient, type AnalytixClient, type AnalytixClientConfig, type AnalytixPlugin } from "@analytix/core";
|
|
2
|
+
export interface InitAnalytixOptions extends AnalytixClientConfig {
|
|
3
|
+
plugins?: AnalytixPlugin[];
|
|
4
|
+
/** Track initial page + history navigation. Default true. */
|
|
5
|
+
autoPage?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Initialize Analytix for vanilla JS / static HTML / Vite SPA.
|
|
9
|
+
* Returns the client instance (`page`, `track`, `identify`, `grantConsent`).
|
|
10
|
+
*/
|
|
11
|
+
export declare function initAnalytix(options: InitAnalytixOptions): AnalytixClient;
|
|
12
|
+
export { createAnalytixClient };
|
|
13
|
+
export type { AnalytixClient, AnalytixClientConfig, AnalytixPlugin };
|
|
14
|
+
declare global {
|
|
15
|
+
interface Window {
|
|
16
|
+
analytix?: AnalytixClient;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Attach client to `window.analytix` for script-tag usage. */
|
|
20
|
+
export declare function exposeAnalytix(client: AnalytixClient): AnalytixClient;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createAnalytixClient, } from "@analytix/core";
|
|
2
|
+
function patchHistory(client) {
|
|
3
|
+
if (typeof window === "undefined")
|
|
4
|
+
return () => undefined;
|
|
5
|
+
const track = () => void client.page({ path: window.location.pathname });
|
|
6
|
+
window.addEventListener("popstate", track);
|
|
7
|
+
const push = history.pushState.bind(history);
|
|
8
|
+
const replace = history.replaceState.bind(history);
|
|
9
|
+
history.pushState = (...args) => {
|
|
10
|
+
push(...args);
|
|
11
|
+
track();
|
|
12
|
+
};
|
|
13
|
+
history.replaceState = (...args) => {
|
|
14
|
+
replace(...args);
|
|
15
|
+
track();
|
|
16
|
+
};
|
|
17
|
+
return () => {
|
|
18
|
+
window.removeEventListener("popstate", track);
|
|
19
|
+
history.pushState = push;
|
|
20
|
+
history.replaceState = replace;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Initialize Analytix for vanilla JS / static HTML / Vite SPA.
|
|
25
|
+
* Returns the client instance (`page`, `track`, `identify`, `grantConsent`).
|
|
26
|
+
*/
|
|
27
|
+
export function initAnalytix(options) {
|
|
28
|
+
const { autoPage = true, ...clientOptions } = options;
|
|
29
|
+
const client = createAnalytixClient(clientOptions);
|
|
30
|
+
if (autoPage && typeof window !== "undefined") {
|
|
31
|
+
void client.ready().then(() => {
|
|
32
|
+
void client.page({ path: window.location.pathname });
|
|
33
|
+
patchHistory(client);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
return client;
|
|
37
|
+
}
|
|
38
|
+
export { createAnalytixClient };
|
|
39
|
+
/** Attach client to `window.analytix` for script-tag usage. */
|
|
40
|
+
export function exposeAnalytix(client) {
|
|
41
|
+
if (typeof window !== "undefined") {
|
|
42
|
+
window.analytix = client;
|
|
43
|
+
}
|
|
44
|
+
return client;
|
|
45
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@analytix/tracker",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Vanilla JS entry point for Analytix (SPA + script tag)",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": ["dist"],
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public",
|
|
18
|
+
"registry": "https://registry.npmjs.org"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/Shashank519915/analytix.git",
|
|
23
|
+
"directory": "packages/tracker"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc",
|
|
27
|
+
"prepublishOnly": "npm run build"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@analytix/core": "^0.3.0"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"typescript": "^5"
|
|
34
|
+
}
|
|
35
|
+
}
|