lucia-sdk 0.7.3 → 0.9.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/CHANGELOG.md +186 -0
- package/README.md +137 -2
- package/dist/README.md +137 -2
- package/dist/__tests__/auto-init.test.d.ts +5 -0
- package/dist/__tests__/integration/auto-init-integration.test.d.ts +9 -0
- package/dist/__tests__/integration/auto-track-integration.test.d.ts +4 -0
- package/dist/__tests__/utils/click-tracker.test.d.ts +4 -0
- package/dist/__tests__/utils/privacy.test.d.ts +4 -0
- package/dist/core/index.d.ts +17 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +3 -3
- package/dist/index.es.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/package.json +2 -2
- package/dist/types.d.ts +19 -1
- package/dist/umd/lucia-sdk-0.9.0.min.js +18 -0
- package/dist/umd/lucia-sdk-latest.min.js +3 -3
- package/dist/utils/click-tracker.d.ts +100 -0
- package/dist/utils/privacy.d.ts +33 -0
- package/dist/utils/session.d.ts +18 -14
- package/package.json +2 -2
- package/dist/umd/lucia-sdk-0.7.3.min.js +0 -18
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
## [0.9.0](https://github.com/ondecentral/Lucia-Browser-SDK/compare/v0.8.0...v0.9.0) (2025-11-20)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* add auto-init with api key provided in script tag ([fa358a7](https://github.com/ondecentral/Lucia-Browser-SDK/commit/fa358a77151203d90252bbe00f44a407b97b129d))
|
|
12
|
+
* add automated click tracking ([af95407](https://github.com/ondecentral/Lucia-Browser-SDK/commit/af95407d021a4dc464e41fd255a20782d9f235b3))
|
|
13
|
+
* use closest to find trackable elements ([aae6ff6](https://github.com/ondecentral/Lucia-Browser-SDK/commit/aae6ff61fd42f447867130921370d22cc10e7761))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Documentation
|
|
17
|
+
|
|
18
|
+
* update readme ([160130c](https://github.com/ondecentral/Lucia-Browser-SDK/commit/160130c9f82fc39b520b89360523b25bfba65ada))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Code Refactoring
|
|
22
|
+
|
|
23
|
+
* optimize click tracking with closest() and add cleanup ([78cf55f](https://github.com/ondecentral/Lucia-Browser-SDK/commit/78cf55f09ff8fbb2ccb69ea50887ec11366e98d1))
|
|
24
|
+
|
|
25
|
+
## [0.8.0](https://github.com/ondecentral/Lucia-Browser-SDK/compare/v0.7.2...v0.8.0) (2025-11-13)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* receive session hash from backend ([8fdd41c](https://github.com/ondecentral/Lucia-Browser-SDK/commit/8fdd41cc37f032bacd7c839d9c31b9e81896e023))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Miscellaneous
|
|
34
|
+
|
|
35
|
+
* update dependencies and ignore package-lock.json ([bc679bc](https://github.com/ondecentral/Lucia-Browser-SDK/commit/bc679bc69d14db9c49a03a4e497c59bbf46d5a37))
|
|
36
|
+
* update release-it ([06561d9](https://github.com/ondecentral/Lucia-Browser-SDK/commit/06561d934379d2ec02a2267a69611eb9da2640c2))
|
|
37
|
+
|
|
38
|
+
## [0.7.2](https://github.com/ondecentral/Lucia-Browser-SDK/compare/v0.7.0...v0.7.2) (2025-10-02)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Bug Fixes
|
|
42
|
+
|
|
43
|
+
* match version to npm for failing publish ([7ae7f59](https://github.com/ondecentral/Lucia-Browser-SDK/commit/7ae7f597bd7731f505421a1e658e6788dbfdf740))
|
|
44
|
+
|
|
45
|
+
## [0.7.0](https://github.com/ondecentral/Lucia-Browser-SDK/compare/v0.6.0...v0.7.0) (2025-10-02)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Features
|
|
49
|
+
|
|
50
|
+
* add new method for new user events - track acquisition ([b56f910](https://github.com/ondecentral/Lucia-Browser-SDK/commit/b56f9103a532d618808a73ece50e8dd9c9b981bc))
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Bug Fixes
|
|
54
|
+
|
|
55
|
+
* fix failing test ([b6c08ae](https://github.com/ondecentral/Lucia-Browser-SDK/commit/b6c08aeb7a66fbed1f2f0a91c91281575004f9b6))
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
### Code Refactoring
|
|
59
|
+
|
|
60
|
+
* update canvas fingerprinting ([41c1877](https://github.com/ondecentral/Lucia-Browser-SDK/commit/41c18776e8118d5acea1899e11e8ab4adafd467a))
|
|
61
|
+
|
|
62
|
+
## [0.6.0](https://github.com/ondecentral/Lucia-Browser-SDK/compare/v0.5.0...v0.6.0) (2025-05-10)
|
|
63
|
+
|
|
64
|
+
### Features
|
|
65
|
+
|
|
66
|
+
- export utility tools ([7014612](https://github.com/ondecentral/Lucia-Browser-SDK/commit/70146126a260e169e6088462f1792dac23fe2fd5))
|
|
67
|
+
|
|
68
|
+
## [0.5.0](https://github.com/ondecentral/Lucia-Browser-SDK/compare/v0.4.0...v0.5.0) (2025-05-10)
|
|
69
|
+
|
|
70
|
+
### Features
|
|
71
|
+
|
|
72
|
+
- add queue to make sure init is called first ([27d2258](https://github.com/ondecentral/Lucia-Browser-SDK/commit/27d2258fd7f2671b018a1fd6c7d3b2da32b8478c))
|
|
73
|
+
- refactor session to use session storage indefinitely ([05f9a81](https://github.com/ondecentral/Lucia-Browser-SDK/commit/05f9a815d2b2bd411525cf6bc2646848b3c3364e))
|
|
74
|
+
- send sdk version info to backend ([d1718f4](https://github.com/ondecentral/Lucia-Browser-SDK/commit/d1718f4040cde9a1f54297562a6ec4c43bc51fd3))
|
|
75
|
+
- sort payload by categories ([4fe9126](https://github.com/ondecentral/Lucia-Browser-SDK/commit/4fe91264dbb344692726e734e422b5310f7db0d1))
|
|
76
|
+
- use sendBeacon to post data ([9cca238](https://github.com/ondecentral/Lucia-Browser-SDK/commit/9cca2381d304992aa05b25083260b7dcfe85f41c))
|
|
77
|
+
|
|
78
|
+
### Bug Fixes
|
|
79
|
+
|
|
80
|
+
- collect only access for storage ([ac31223](https://github.com/ondecentral/Lucia-Browser-SDK/commit/ac3122307f8e379b6dcb26f1f3015456c5303e27))
|
|
81
|
+
- fix saving and retrieving session data ([5a7fd74](https://github.com/ondecentral/Lucia-Browser-SDK/commit/5a7fd740da6070c7ff7a8f1c44dc03b880cdccc0))
|
|
82
|
+
- fix utm collection ([07a1701](https://github.com/ondecentral/Lucia-Browser-SDK/commit/07a17016c94fb600066c25bcc8116d17fac918f9))
|
|
83
|
+
- put back the session structure expected by current backend ([872f3b9](https://github.com/ondecentral/Lucia-Browser-SDK/commit/872f3b97ee78ce559ef8681ca96ac238f132e46d))
|
|
84
|
+
|
|
85
|
+
### Tests
|
|
86
|
+
|
|
87
|
+
- add integration tests ([b773c70](https://github.com/ondecentral/Lucia-Browser-SDK/commit/b773c70516bcd6180ca25d0c9b8f7f54f5a0016f))
|
|
88
|
+
- add tests ([6846812](https://github.com/ondecentral/Lucia-Browser-SDK/commit/6846812104ec69a343114fc9a9039cb884952d9a))
|
|
89
|
+
- add tests for ethereum module ([82eefda](https://github.com/ondecentral/Lucia-Browser-SDK/commit/82eefda876dec4c233f140f185ede65b37ca9f3e))
|
|
90
|
+
- add tests for solana module ([c0f94a0](https://github.com/ondecentral/Lucia-Browser-SDK/commit/c0f94a050e1412081e24ff05fc2f2ea046c9621c))
|
|
91
|
+
- reduce mocks through spys ([3344a39](https://github.com/ondecentral/Lucia-Browser-SDK/commit/3344a398c28268ef6eca8d947d00ea53ba833cb0))
|
|
92
|
+
- tidy up data tools tests ([0e36f1f](https://github.com/ondecentral/Lucia-Browser-SDK/commit/0e36f1f7eec682efde87400d5a06cb41f733412d))
|
|
93
|
+
|
|
94
|
+
### Code Refactoring
|
|
95
|
+
|
|
96
|
+
- collect redirect hash explicitly ([a99a40a](https://github.com/ondecentral/Lucia-Browser-SDK/commit/a99a40a7df1526a5d9c5821e877bd339181061f2))
|
|
97
|
+
- move agent parsing to backend ([83271c2](https://github.com/ondecentral/Lucia-Browser-SDK/commit/83271c2f7160abb491912c819bf93fcb89b9d572))
|
|
98
|
+
- refactor session management ([cc15809](https://github.com/ondecentral/Lucia-Browser-SDK/commit/cc158093579fd2e1a2746d1aa2c327844d51c0f1))
|
|
99
|
+
- refactor user data and add more tests for it ([5f82c6a](https://github.com/ondecentral/Lucia-Browser-SDK/commit/5f82c6ac5dbaf3531d807c734a81819184e2685d))
|
|
100
|
+
- remove collecting data from analytics events ([a36c8e2](https://github.com/ondecentral/Lucia-Browser-SDK/commit/a36c8e289f60df7fd0fb5c81598d4fcaa6cc3833))
|
|
101
|
+
|
|
102
|
+
### Miscellaneous
|
|
103
|
+
|
|
104
|
+
- remove unused udata and add more tests for data collection ([68f0fbb](https://github.com/ondecentral/Lucia-Browser-SDK/commit/68f0fbbc4b35f2f4c55ba8b092f7eed7be9484c5))
|
|
105
|
+
- replace logging in wallet utils ([9f4da81](https://github.com/ondecentral/Lucia-Browser-SDK/commit/9f4da81c892c2ebe76cec70e3143cb670114fc3e))
|
|
106
|
+
|
|
107
|
+
## [0.4.0](https://github.com/ondecentral/Lucia-Browser-SDK/compare/v0.3.0...v0.4.0) (2025-04-15)
|
|
108
|
+
|
|
109
|
+
### Features
|
|
110
|
+
|
|
111
|
+
- ethereum and solana browser wallet detection ([0117ba4](https://github.com/ondecentral/Lucia-Browser-SDK/commit/0117ba43b2cba4bfd8c78da8f1bcee21ba11695f))
|
|
112
|
+
- ethereum and solana browser wallet detection ([ea61012](https://github.com/ondecentral/Lucia-Browser-SDK/commit/ea61012f9892914481b377ef8339c1ccbcd73edb))
|
|
113
|
+
- new wallet types and framework for easily adding new wallets ([c99d3a8](https://github.com/ondecentral/Lucia-Browser-SDK/commit/c99d3a875e14980d15cc9f3030194939e29d7026))
|
|
114
|
+
|
|
115
|
+
## [0.3.0](https://github.com/ondecentral/Lucia-Browser-SDK/compare/v0.2.0...v0.3.0) (2025-03-14)
|
|
116
|
+
|
|
117
|
+
### Features
|
|
118
|
+
|
|
119
|
+
- add walletName to sendWalletInfo ([50944b0](https://github.com/ondecentral/Lucia-Browser-SDK/commit/50944b0f37d1492b47dbab1bb07b8281edabaf37))
|
|
120
|
+
|
|
121
|
+
### Documentation
|
|
122
|
+
|
|
123
|
+
- type of walletName is Metamask | Phantom ([1ca2008](https://github.com/ondecentral/Lucia-Browser-SDK/commit/1ca20088567e51a481e7bbd56cdea73d7cd45091))
|
|
124
|
+
|
|
125
|
+
## [0.2.0](https://github.com/ondecentral/Lucia-Browser-SDK/compare/v0.1.0...v0.2.0) (2025-03-12)
|
|
126
|
+
|
|
127
|
+
### Features
|
|
128
|
+
|
|
129
|
+
- collect and send utm params on init ([0fa6e85](https://github.com/ondecentral/Lucia-Browser-SDK/commit/0fa6e85b79f69c2b402bc55f8bf896a5fda4ba54))
|
|
130
|
+
|
|
131
|
+
## [0.1.0](https://github.com/ondecentral/Lucia-Browser-SDK/compare/v0.0.5...v0.1.0) (2025-01-23)
|
|
132
|
+
|
|
133
|
+
### Features
|
|
134
|
+
|
|
135
|
+
- add github releases ([86f2638](https://github.com/ondecentral/Lucia-Browser-SDK/commit/86f2638aa48eb66d8b4e8537314569ae25dd0b9d))
|
|
136
|
+
|
|
137
|
+
## [0.0.5](https://github.com/ondecentral/Lucia-Browser-SDK/compare/v0.0.4...v0.0.5) (2025-01-23)
|
|
138
|
+
|
|
139
|
+
### Bug Fixes
|
|
140
|
+
|
|
141
|
+
- fix changelog generation ([4797697](https://github.com/ondecentral/Lucia-Browser-SDK/commit/47976978ccb3866d510919c974dc73d304786953))
|
|
142
|
+
- fix release and publish ([8de68e6](https://github.com/ondecentral/Lucia-Browser-SDK/commit/8de68e6fe5bbef2b3d4e99262dc6f44d55241bc3))
|
|
143
|
+
|
|
144
|
+
## [0.0.4] - 2024-03-19
|
|
145
|
+
|
|
146
|
+
### Features
|
|
147
|
+
|
|
148
|
+
- add alpha release workflow
|
|
149
|
+
- add release workflow
|
|
150
|
+
|
|
151
|
+
### Bug Fixes
|
|
152
|
+
|
|
153
|
+
- fix typescript error for global object
|
|
154
|
+
- fix changelog generation
|
|
155
|
+
- fix release workflow
|
|
156
|
+
|
|
157
|
+
### Code Refactoring
|
|
158
|
+
|
|
159
|
+
- split release and publish workflows
|
|
160
|
+
|
|
161
|
+
## [0.0.3] - 2024-03-18
|
|
162
|
+
|
|
163
|
+
### Features
|
|
164
|
+
|
|
165
|
+
- initial SDK setup
|
|
166
|
+
- add tracking methods
|
|
167
|
+
- add user info methods
|
|
168
|
+
|
|
169
|
+
### Bug Fixes
|
|
170
|
+
|
|
171
|
+
- fix initialization process
|
|
172
|
+
- fix http client base url
|
|
173
|
+
|
|
174
|
+
## [0.0.2] - 2024-03-17
|
|
175
|
+
|
|
176
|
+
### Features
|
|
177
|
+
|
|
178
|
+
- add core SDK functionality
|
|
179
|
+
- add basic tracking methods
|
|
180
|
+
|
|
181
|
+
## [0.0.1] - 2024-03-16
|
|
182
|
+
|
|
183
|
+
### Features
|
|
184
|
+
|
|
185
|
+
- initial release
|
|
186
|
+
- basic SDK structure
|
package/README.md
CHANGED
|
@@ -24,20 +24,150 @@ yarn add lucia-sdk
|
|
|
24
24
|
|
|
25
25
|
You can add the following script to use global `LuciaSDK` object.
|
|
26
26
|
|
|
27
|
+
**Option 1: Auto-initialization (Recommended)**
|
|
28
|
+
|
|
29
|
+
The SDK will automatically initialize when you provide the `data-api-key` attribute:
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<script src="https://cdn.luciaprotocol.com/lucia-sdk-latest.min.js" data-api-key="your-api-key-here"></script>
|
|
27
33
|
```
|
|
34
|
+
|
|
35
|
+
Optional configuration attributes:
|
|
36
|
+
|
|
37
|
+
- `data-api-key` (required) - Your Lucia API key
|
|
38
|
+
- `data-debug-url` (optional) - Custom debug endpoint URL
|
|
39
|
+
- `data-auto-track-clicks` (optional) - Enable automatic click tracking (`"true"` or `"false"`)
|
|
40
|
+
- `data-track-selectors` (optional) - Custom CSS selectors for click tracking (comma-separated)
|
|
41
|
+
|
|
42
|
+
**Option 2: Manual initialization**
|
|
43
|
+
|
|
44
|
+
Load the script without attributes and initialize programmatically:
|
|
45
|
+
|
|
46
|
+
```html
|
|
28
47
|
<script src="https://cdn.luciaprotocol.com/lucia-sdk-latest.min.js"></script>
|
|
48
|
+
<script>
|
|
49
|
+
LuciaSDK.init({
|
|
50
|
+
apiKey: 'your-api-key-here',
|
|
51
|
+
debugURL: 'https://custom-debug-url.com', // optional
|
|
52
|
+
});
|
|
53
|
+
</script>
|
|
29
54
|
```
|
|
30
55
|
|
|
31
56
|
## Usage
|
|
32
57
|
|
|
33
58
|
### Initialize the SDK
|
|
34
59
|
|
|
60
|
+
#### For CDN (Manual Initialization)
|
|
61
|
+
|
|
35
62
|
```javascript
|
|
36
63
|
LuciaSDK.init({
|
|
37
|
-
apiKey,
|
|
64
|
+
apiKey: 'your-api-key-here',
|
|
65
|
+
debugURL: 'https://custom-debug-url.com', // optional
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### For npm/yarn Installation
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
import LuciaSDK from 'lucia-sdk';
|
|
73
|
+
|
|
74
|
+
await LuciaSDK.init({
|
|
75
|
+
apiKey: 'your-api-key-here',
|
|
76
|
+
autoTrackClicks: true, // optional: enable automatic click tracking
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### For Next.js
|
|
81
|
+
|
|
82
|
+
The SDK seamlessly works with Next.js using both CDN auto-init and npm import:
|
|
83
|
+
|
|
84
|
+
```jsx
|
|
85
|
+
import Script from 'next/script';
|
|
86
|
+
import LuciaSDK from 'lucia-sdk';
|
|
87
|
+
|
|
88
|
+
export default function Page() {
|
|
89
|
+
const handleClick = () => {
|
|
90
|
+
// NPM import works with CDN-initialized instance
|
|
91
|
+
LuciaSDK.buttonClick('cta-button');
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<>
|
|
96
|
+
<Script
|
|
97
|
+
src="https://cdn.luciaprotocol.com/lucia-sdk-latest.min.js"
|
|
98
|
+
data-api-key="your-api-key-here"
|
|
99
|
+
strategy="afterInteractive"
|
|
100
|
+
/>
|
|
101
|
+
<button onClick={handleClick}>Click me</button>
|
|
102
|
+
</>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Automated Click Tracking
|
|
108
|
+
|
|
109
|
+
Lucia SDK provides zero-config automated click tracking. When enabled, it automatically tracks clicks on buttons, links, and other interactive elements.
|
|
110
|
+
|
|
111
|
+
#### Enable via CDN
|
|
112
|
+
|
|
113
|
+
```html
|
|
114
|
+
<script
|
|
115
|
+
src="https://cdn.luciaprotocol.com/lucia-sdk-latest.min.js"
|
|
116
|
+
data-api-key="your-api-key-here"
|
|
117
|
+
data-auto-track-clicks="true"
|
|
118
|
+
></script>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### Enable Programmatically
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
await LuciaSDK.init({
|
|
125
|
+
apiKey: 'your-api-key-here',
|
|
126
|
+
autoTrackClicks: true, // Enable with defaults
|
|
38
127
|
});
|
|
128
|
+
|
|
129
|
+
// Or with custom configuration
|
|
130
|
+
await LuciaSDK.init({
|
|
131
|
+
apiKey: 'your-api-key-here',
|
|
132
|
+
autoTrackClicks: {
|
|
133
|
+
enabled: true,
|
|
134
|
+
selectors: ['button', '.cta', '[data-track]'], // Custom selectors
|
|
135
|
+
ignore: ['.no-track'], // Elements to ignore
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### Element-Level Control
|
|
141
|
+
|
|
142
|
+
Add tracking attributes to specific elements:
|
|
143
|
+
|
|
144
|
+
```html
|
|
145
|
+
<!-- Explicit tracking with custom identifier -->
|
|
146
|
+
<button data-lucia-track="signup-cta">Sign Up</button>
|
|
147
|
+
|
|
148
|
+
<!-- Add metadata to tracked clicks -->
|
|
149
|
+
<button data-lucia-track="purchase-btn" data-lucia-meta-variant="primary" data-lucia-meta-location="hero">
|
|
150
|
+
Buy Now
|
|
151
|
+
</button>
|
|
152
|
+
|
|
153
|
+
<!-- Ignore specific elements -->
|
|
154
|
+
<button data-lucia-ignore>Don't Track This</button>
|
|
39
155
|
```
|
|
40
156
|
|
|
157
|
+
**Default Tracked Elements:**
|
|
158
|
+
|
|
159
|
+
- `<button>` elements
|
|
160
|
+
- `<a>` elements with `href` attribute
|
|
161
|
+
- Elements with `role="button"`
|
|
162
|
+
- Any element with `data-lucia-track` attribute
|
|
163
|
+
|
|
164
|
+
**Privacy Features:**
|
|
165
|
+
|
|
166
|
+
- Automatically ignores password inputs
|
|
167
|
+
- Skips credit card fields
|
|
168
|
+
- Filters sensitive data from text content
|
|
169
|
+
- Respects `data-lucia-ignore` attribute
|
|
170
|
+
|
|
41
171
|
### Track events
|
|
42
172
|
|
|
43
173
|
Page views, conversions, and user information can be tracked using the following methods:
|
|
@@ -63,7 +193,12 @@ LuciaSDK.trackConversion(
|
|
|
63
193
|
},
|
|
64
194
|
);
|
|
65
195
|
|
|
66
|
-
|
|
196
|
+
// Manual click tracking (optional with auto-tracking enabled)
|
|
197
|
+
LuciaSDK.buttonClick('cta-button', {
|
|
198
|
+
elementType: 'button',
|
|
199
|
+
text: 'Sign Up Now',
|
|
200
|
+
meta: { variant: 'primary', location: 'hero' },
|
|
201
|
+
});
|
|
67
202
|
|
|
68
203
|
LuciaSDK.sendWalletInfo('0x1234567890', 59141);
|
|
69
204
|
```
|
package/dist/README.md
CHANGED
|
@@ -24,20 +24,150 @@ yarn add lucia-sdk
|
|
|
24
24
|
|
|
25
25
|
You can add the following script to use global `LuciaSDK` object.
|
|
26
26
|
|
|
27
|
+
**Option 1: Auto-initialization (Recommended)**
|
|
28
|
+
|
|
29
|
+
The SDK will automatically initialize when you provide the `data-api-key` attribute:
|
|
30
|
+
|
|
31
|
+
```html
|
|
32
|
+
<script src="https://cdn.luciaprotocol.com/lucia-sdk-latest.min.js" data-api-key="your-api-key-here"></script>
|
|
27
33
|
```
|
|
34
|
+
|
|
35
|
+
Optional configuration attributes:
|
|
36
|
+
|
|
37
|
+
- `data-api-key` (required) - Your Lucia API key
|
|
38
|
+
- `data-debug-url` (optional) - Custom debug endpoint URL
|
|
39
|
+
- `data-auto-track-clicks` (optional) - Enable automatic click tracking (`"true"` or `"false"`)
|
|
40
|
+
- `data-track-selectors` (optional) - Custom CSS selectors for click tracking (comma-separated)
|
|
41
|
+
|
|
42
|
+
**Option 2: Manual initialization**
|
|
43
|
+
|
|
44
|
+
Load the script without attributes and initialize programmatically:
|
|
45
|
+
|
|
46
|
+
```html
|
|
28
47
|
<script src="https://cdn.luciaprotocol.com/lucia-sdk-latest.min.js"></script>
|
|
48
|
+
<script>
|
|
49
|
+
LuciaSDK.init({
|
|
50
|
+
apiKey: 'your-api-key-here',
|
|
51
|
+
debugURL: 'https://custom-debug-url.com', // optional
|
|
52
|
+
});
|
|
53
|
+
</script>
|
|
29
54
|
```
|
|
30
55
|
|
|
31
56
|
## Usage
|
|
32
57
|
|
|
33
58
|
### Initialize the SDK
|
|
34
59
|
|
|
60
|
+
#### For CDN (Manual Initialization)
|
|
61
|
+
|
|
35
62
|
```javascript
|
|
36
63
|
LuciaSDK.init({
|
|
37
|
-
apiKey,
|
|
64
|
+
apiKey: 'your-api-key-here',
|
|
65
|
+
debugURL: 'https://custom-debug-url.com', // optional
|
|
66
|
+
});
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### For npm/yarn Installation
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
import LuciaSDK from 'lucia-sdk';
|
|
73
|
+
|
|
74
|
+
await LuciaSDK.init({
|
|
75
|
+
apiKey: 'your-api-key-here',
|
|
76
|
+
autoTrackClicks: true, // optional: enable automatic click tracking
|
|
77
|
+
});
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### For Next.js
|
|
81
|
+
|
|
82
|
+
The SDK seamlessly works with Next.js using both CDN auto-init and npm import:
|
|
83
|
+
|
|
84
|
+
```jsx
|
|
85
|
+
import Script from 'next/script';
|
|
86
|
+
import LuciaSDK from 'lucia-sdk';
|
|
87
|
+
|
|
88
|
+
export default function Page() {
|
|
89
|
+
const handleClick = () => {
|
|
90
|
+
// NPM import works with CDN-initialized instance
|
|
91
|
+
LuciaSDK.buttonClick('cta-button');
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<>
|
|
96
|
+
<Script
|
|
97
|
+
src="https://cdn.luciaprotocol.com/lucia-sdk-latest.min.js"
|
|
98
|
+
data-api-key="your-api-key-here"
|
|
99
|
+
strategy="afterInteractive"
|
|
100
|
+
/>
|
|
101
|
+
<button onClick={handleClick}>Click me</button>
|
|
102
|
+
</>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Automated Click Tracking
|
|
108
|
+
|
|
109
|
+
Lucia SDK provides zero-config automated click tracking. When enabled, it automatically tracks clicks on buttons, links, and other interactive elements.
|
|
110
|
+
|
|
111
|
+
#### Enable via CDN
|
|
112
|
+
|
|
113
|
+
```html
|
|
114
|
+
<script
|
|
115
|
+
src="https://cdn.luciaprotocol.com/lucia-sdk-latest.min.js"
|
|
116
|
+
data-api-key="your-api-key-here"
|
|
117
|
+
data-auto-track-clicks="true"
|
|
118
|
+
></script>
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
#### Enable Programmatically
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
await LuciaSDK.init({
|
|
125
|
+
apiKey: 'your-api-key-here',
|
|
126
|
+
autoTrackClicks: true, // Enable with defaults
|
|
38
127
|
});
|
|
128
|
+
|
|
129
|
+
// Or with custom configuration
|
|
130
|
+
await LuciaSDK.init({
|
|
131
|
+
apiKey: 'your-api-key-here',
|
|
132
|
+
autoTrackClicks: {
|
|
133
|
+
enabled: true,
|
|
134
|
+
selectors: ['button', '.cta', '[data-track]'], // Custom selectors
|
|
135
|
+
ignore: ['.no-track'], // Elements to ignore
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### Element-Level Control
|
|
141
|
+
|
|
142
|
+
Add tracking attributes to specific elements:
|
|
143
|
+
|
|
144
|
+
```html
|
|
145
|
+
<!-- Explicit tracking with custom identifier -->
|
|
146
|
+
<button data-lucia-track="signup-cta">Sign Up</button>
|
|
147
|
+
|
|
148
|
+
<!-- Add metadata to tracked clicks -->
|
|
149
|
+
<button data-lucia-track="purchase-btn" data-lucia-meta-variant="primary" data-lucia-meta-location="hero">
|
|
150
|
+
Buy Now
|
|
151
|
+
</button>
|
|
152
|
+
|
|
153
|
+
<!-- Ignore specific elements -->
|
|
154
|
+
<button data-lucia-ignore>Don't Track This</button>
|
|
39
155
|
```
|
|
40
156
|
|
|
157
|
+
**Default Tracked Elements:**
|
|
158
|
+
|
|
159
|
+
- `<button>` elements
|
|
160
|
+
- `<a>` elements with `href` attribute
|
|
161
|
+
- Elements with `role="button"`
|
|
162
|
+
- Any element with `data-lucia-track` attribute
|
|
163
|
+
|
|
164
|
+
**Privacy Features:**
|
|
165
|
+
|
|
166
|
+
- Automatically ignores password inputs
|
|
167
|
+
- Skips credit card fields
|
|
168
|
+
- Filters sensitive data from text content
|
|
169
|
+
- Respects `data-lucia-ignore` attribute
|
|
170
|
+
|
|
41
171
|
### Track events
|
|
42
172
|
|
|
43
173
|
Page views, conversions, and user information can be tracked using the following methods:
|
|
@@ -63,7 +193,12 @@ LuciaSDK.trackConversion(
|
|
|
63
193
|
},
|
|
64
194
|
);
|
|
65
195
|
|
|
66
|
-
|
|
196
|
+
// Manual click tracking (optional with auto-tracking enabled)
|
|
197
|
+
LuciaSDK.buttonClick('cta-button', {
|
|
198
|
+
elementType: 'button',
|
|
199
|
+
text: 'Sign Up Now',
|
|
200
|
+
meta: { variant: 'primary', location: 'hero' },
|
|
201
|
+
});
|
|
67
202
|
|
|
68
203
|
LuciaSDK.sendWalletInfo('0x1234567890', 59141);
|
|
69
204
|
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration tests for auto-initialization with hybrid CDN + npm usage
|
|
3
|
+
*
|
|
4
|
+
* NOTE: These tests focus on the conceptual aspects of auto-init that can be tested
|
|
5
|
+
* in a Jest environment. Full CDN auto-init behavior (script tag detection,
|
|
6
|
+
* DOMContentLoaded, automatic initialization) must be tested manually using:
|
|
7
|
+
* demo/auto-init-demo.html in a real browser environment.
|
|
8
|
+
*/
|
|
9
|
+
import '@testing-library/jest-dom';
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import BaseClass from '../base';
|
|
2
|
+
import { ClickEventMetadata } from '../types';
|
|
2
3
|
declare class LuciaSDK extends BaseClass {
|
|
4
|
+
private clickTracker;
|
|
3
5
|
authenticate(): void;
|
|
4
6
|
/**
|
|
5
7
|
* Initializes the SDK with the provided configuration
|
|
6
8
|
*/
|
|
7
9
|
init(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Initialize automated click tracking if enabled
|
|
12
|
+
*/
|
|
13
|
+
private initAutoTracking;
|
|
14
|
+
/**
|
|
15
|
+
* Handle automatically tracked click events
|
|
16
|
+
*/
|
|
17
|
+
private handleAutoTrackedClick;
|
|
8
18
|
/**
|
|
9
19
|
* Sends user information to the server
|
|
10
20
|
* @param userId The user's ID, e.g. email, wallet address, etc.
|
|
@@ -25,9 +35,10 @@ declare class LuciaSDK extends BaseClass {
|
|
|
25
35
|
trackConversion(eventTag: string, amount: number, eventDetails: object): Promise<void>;
|
|
26
36
|
/**
|
|
27
37
|
* Sends button click information to the server
|
|
28
|
-
* @param button The button that was clicked
|
|
38
|
+
* @param button The button identifier that was clicked
|
|
39
|
+
* @param metadata Optional metadata about the click event (elementType, text, href, meta)
|
|
29
40
|
*/
|
|
30
|
-
buttonClick(button: string): Promise<void>;
|
|
41
|
+
buttonClick(button: string, metadata?: ClickEventMetadata): Promise<void>;
|
|
31
42
|
/**
|
|
32
43
|
* Sends wallet information to the server
|
|
33
44
|
* @param walletAddress The wallet address of the user
|
|
@@ -45,5 +56,9 @@ declare class LuciaSDK extends BaseClass {
|
|
|
45
56
|
* @returns false if MetaMask is not connected, otherwise returns the wallet address
|
|
46
57
|
*/
|
|
47
58
|
checkMetaMaskConnection(): any;
|
|
59
|
+
/**
|
|
60
|
+
* Clean up SDK resources (mainly for testing)
|
|
61
|
+
*/
|
|
62
|
+
destroy(): void;
|
|
48
63
|
}
|
|
49
64
|
export default LuciaSDK;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SDK } from './types';
|
|
2
2
|
import { getBrowserData, getWalletData, getUtmParams, safeAccess, filterObject, getCanvasFingerprint, isTouchEnabled, getApplePayAvailable, getContrastPreference, getColorGamut } from './utils/data';
|
|
3
|
+
export declare const __resetInstance: () => void;
|
|
3
4
|
declare const LuciaSDK: SDK;
|
|
4
5
|
export default LuciaSDK;
|
|
5
6
|
export { getBrowserData, getWalletData, getUtmParams, safeAccess, filterObject, getCanvasFingerprint, isTouchEnabled, getApplePayAvailable, getContrastPreference, getColorGamut, };
|