@brainfish-ai/web-tracker 0.0.1-alpha.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 ADDED
@@ -0,0 +1,129 @@
1
+ # Web SDK
2
+
3
+ ## Installation
4
+
5
+ Steps to install the Brainfish Tracker SDK in your web application.
6
+
7
+ ### Install dependencies
8
+
9
+ ```bash
10
+ npm install @brainfish-ai/web-tracker
11
+ ```
12
+
13
+ ### Initialize
14
+
15
+ ```tsx
16
+ import { Tracker } from '@brainfish-ai/web-tracker';
17
+
18
+ const tracker = new Tracker({
19
+ accessKey: '{accessKey}',
20
+ trackScreenViews: true,
21
+ // trackAttributes: true,
22
+ // trackOutgoingLinks: true,
23
+ });
24
+ ```
25
+
26
+ #### Config
27
+
28
+ <SdkConfig />
29
+
30
+ ### Ready!
31
+
32
+ You're now ready to use the library.
33
+
34
+ ```typescript
35
+ // Sends an event with payload foo: bar
36
+ tracker.event('my_event', { foo: 'bar' });
37
+
38
+ // Identify with user id
39
+ tracker.setUserId('123');
40
+
41
+ // or with additional data
42
+ tracker.setUser({
43
+ userId: '123',
44
+ firstName: 'John',
45
+ lastName: 'Doe',
46
+ email: 'john.doe@brainfi.sh',
47
+ });
48
+
49
+ // Increment a property
50
+ tracker.increment('app_opened'); // increment by 1
51
+ tracker.increment('app_opened', 5); // increment by 5
52
+
53
+ // Decrement a property
54
+ tracker.decrement('app_opened'); // decrement by 1
55
+ tracker.decrement('app_opened', 5); // decrement by 5
56
+ ```
57
+
58
+ </Steps>
59
+
60
+ ## Usage
61
+
62
+ ### Track event
63
+
64
+ ```typescript
65
+ tracker.event('my_event', { foo: 'bar' });
66
+ ```
67
+
68
+ ### Identify
69
+
70
+ #### Set user Id
71
+
72
+ Keep track of your users by identifying them with a unique id. This is a good features if you have things behind a login and want to track user behavior.
73
+
74
+ <PersonalDataWarning />
75
+
76
+ ```typescript
77
+ const userId = '123';
78
+ tracker.setUserId(userId);
79
+ ```
80
+
81
+ #### Additional data
82
+
83
+ This method does the same as `setUserId` but also allows you to update the user with additional data.
84
+
85
+ <PersonalDataWarning />
86
+
87
+ ```typescript
88
+ const userId = '123';
89
+ tracker.setUser({
90
+ userId,
91
+ // firstName?: string;
92
+ // lastName?: string;
93
+ // email?: string;
94
+ // avatar?: string;
95
+ // properties?: Record<string, unknown>;
96
+ });
97
+ ```
98
+
99
+ #### Increment property
100
+
101
+ Increment a property on the user.
102
+
103
+ ```typescript
104
+ // Increment by 1
105
+ tracker.increment('app_opened');
106
+
107
+ // Increment by 5
108
+ tracker.increment('app_opened', 5);
109
+ ```
110
+
111
+ #### Decrement property
112
+
113
+ Decrement a property on the user.
114
+
115
+ ```typescript
116
+ // Increment by 1
117
+ tracker.decrement('app_opened');
118
+
119
+ // Increment by 5
120
+ tracker.decrement('app_opened', 5);
121
+ ```
122
+
123
+ #### Clear / Logout
124
+
125
+ Clear the user id and all the data.
126
+
127
+ ```typescript
128
+ tracker.clear();
129
+ ```
@@ -0,0 +1 @@
1
+ "use strict";const r=require("./index.cjs.js");(c=>{if(c.tracker&&"q"in c.tracker){const e=c.tracker.q||[],i=new r.Tracker(e.shift()[1]);e.forEach((r=>{r[0]in i&&i[r[0]](...r.slice(1))})),c.tracker=(r,...c)=>{const e=i[r]?i[r].bind(i):void 0;"function"==typeof e&&e(...c)}}})(window);
package/dist/cdn.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ declare global {
2
+ interface Window {
3
+ tracker: {
4
+ q?: [string, ...any[]];
5
+ (method: string, ...args: any[]): void;
6
+ };
7
+ }
8
+ }
9
+ export {};
package/dist/cdn.js ADDED
@@ -0,0 +1 @@
1
+ import{Tracker as n}from"./index.js";(r=>{if(r.tracker&&"q"in r.tracker){const i=r.tracker.q||[],o=new n(i.shift()[1]);i.forEach((n=>{n[0]in o&&o[n[0]](...n.slice(1))})),r.tracker=(n,...r)=>{const i=o[n]?o[n].bind(o):void 0;"function"==typeof i?i(...r):console.warn(`tracker.js: ${n} is not a function`)}}})(window);