oanvoanalytics 2.0.0-beta.1

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.
@@ -0,0 +1,24 @@
1
+ export interface OanvoConfig {
2
+ key: string;
3
+ endpoint?: string;
4
+ supabaseKey?: string;
5
+ }
6
+ export interface EventMetadata {
7
+ [key: string]: any;
8
+ }
9
+ declare class OanvoTracker {
10
+ private apiKey;
11
+ private apiEndpoint;
12
+ private supabaseKey;
13
+ private visitorId;
14
+ private sessionId;
15
+ private initialized;
16
+ init(config: OanvoConfig): void;
17
+ track(eventType: string, metadata?: EventMetadata): void;
18
+ page(path?: string, metadata?: EventMetadata): void;
19
+ identify(userId: string, traits?: EventMetadata): void;
20
+ private getOrCreateStorage;
21
+ private attachSpaListeners;
22
+ }
23
+ export declare const Oanvo: OanvoTracker;
24
+ export default Oanvo;
package/dist/index.js ADDED
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Oanvo = void 0;
4
+ class OanvoTracker {
5
+ constructor() {
6
+ this.apiKey = null;
7
+ this.apiEndpoint = 'https://vjsafhlkwsemsnufmwhh.supabase.co/rest/v1/events';
8
+ this.supabaseKey = 'sb_publishable_1RTxvl5fYE0k3gbV8PBT-A_l0Js2HgQ';
9
+ this.visitorId = '';
10
+ this.sessionId = '';
11
+ this.initialized = false;
12
+ }
13
+ init(config) {
14
+ if (typeof window === 'undefined')
15
+ return;
16
+ this.apiKey = config.key;
17
+ if (config.endpoint)
18
+ this.apiEndpoint = config.endpoint;
19
+ if (config.supabaseKey)
20
+ this.supabaseKey = config.supabaseKey;
21
+ this.visitorId = this.getOrCreateStorage('_oanvo_vid', false, 'vis');
22
+ this.sessionId = this.getOrCreateStorage('_oanvo_sid', true, 'ses');
23
+ if (!this.initialized) {
24
+ this.initialized = true;
25
+ this.track('PAGEVIEW', {
26
+ screen: `${window.innerWidth}x${window.innerHeight}`,
27
+ lang: navigator.language
28
+ });
29
+ this.attachSpaListeners();
30
+ }
31
+ }
32
+ track(eventType, metadata) {
33
+ if (typeof window === 'undefined' || !this.apiKey) {
34
+ console.warn('[Oanvo] Cannot track event: missing apiKey or not in browser environment');
35
+ return;
36
+ }
37
+ const payload = {
38
+ api_key: this.apiKey,
39
+ event_type: eventType,
40
+ url: window.location.href,
41
+ path: window.location.pathname,
42
+ referrer: document.referrer || null,
43
+ title: document.title || null,
44
+ visitor_id: this.visitorId,
45
+ session_id: this.sessionId,
46
+ metadata: metadata || {}
47
+ };
48
+ fetch(this.apiEndpoint, {
49
+ method: 'POST',
50
+ headers: {
51
+ 'apikey': this.supabaseKey,
52
+ 'Authorization': `Bearer ${this.supabaseKey}`,
53
+ 'Content-Type': 'application/json',
54
+ 'Prefer': 'return=minimal'
55
+ },
56
+ body: JSON.stringify(payload),
57
+ keepalive: true
58
+ }).catch(err => {
59
+ console.warn('[Oanvo] Transmission failed:', err);
60
+ });
61
+ }
62
+ page(path, metadata) {
63
+ const meta = metadata || {};
64
+ if (path)
65
+ meta.custom_path = path;
66
+ this.track('PAGEVIEW', meta);
67
+ }
68
+ identify(userId, traits) {
69
+ this.track('IDENTIFY', { user_id: userId, traits: traits || {} });
70
+ }
71
+ getOrCreateStorage(key, isSession, prefix) {
72
+ try {
73
+ const storage = isSession ? sessionStorage : localStorage;
74
+ let val = storage.getItem(key);
75
+ if (!val) {
76
+ val = `${prefix}_${Math.random().toString(36).substring(2, 10)}${Date.now().toString(36)}`;
77
+ storage.setItem(key, val);
78
+ }
79
+ return val;
80
+ }
81
+ catch {
82
+ return `${prefix}_${Date.now()}`;
83
+ }
84
+ }
85
+ attachSpaListeners() {
86
+ let lastPath = window.location.pathname;
87
+ const checkPath = () => {
88
+ if (window.location.pathname !== lastPath) {
89
+ lastPath = window.location.pathname;
90
+ this.track('PAGEVIEW');
91
+ }
92
+ };
93
+ window.addEventListener('popstate', checkPath);
94
+ const origPush = history.pushState;
95
+ if (origPush) {
96
+ history.pushState = function (...args) {
97
+ origPush.apply(this, args);
98
+ checkPath();
99
+ };
100
+ }
101
+ const origReplace = history.replaceState;
102
+ if (origReplace) {
103
+ history.replaceState = function (...args) {
104
+ origReplace.apply(this, args);
105
+ checkPath();
106
+ };
107
+ }
108
+ }
109
+ }
110
+ exports.Oanvo = new OanvoTracker();
111
+ exports.default = exports.Oanvo;
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "oanvoanalytics",
3
+ "version": "2.0.0-beta.1",
4
+ "description": "Ultra-lightweight zero-knowledge edge analytics tracker for Oanvo",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "build": "tsc"
13
+ },
14
+ "keywords": [
15
+ "analytics",
16
+ "privacy",
17
+ "edge",
18
+ "oanvo",
19
+ "oanvoanalytics",
20
+ "telemetry",
21
+ "wasm",
22
+ "zero-knowledge"
23
+ ],
24
+ "author": "Oanvo Team",
25
+ "license": "MIT",
26
+ "publishConfig": {
27
+ "access": "public"
28
+ }
29
+ }