@incognia/web-sdk 1.4.0 → 1.5.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.
package/README.md CHANGED
@@ -1,158 +1,8 @@
1
- # Incognia Web SDK
1
+ ![Alt logoImage][logo]
2
2
 
3
- The Incognia SDK for the web.
3
+ # Incognia SDK
4
4
 
5
- Documentation can be found at <https://developer.incognia.com/docs>
5
+ To integrate the SDK, check our [documentation][docs].
6
6
 
7
- ## Installation
8
-
9
- ### npm
10
-
11
- ```sh
12
- npm install @incognia/web-sdk
13
- ```
14
-
15
- ### pnpm
16
-
17
- ```sh
18
- pnpm install @incognia/web-sdk
19
- ```
20
-
21
- ### yarn
22
-
23
- ```sh
24
- yarn add @incognia/web-sdk
25
- ```
26
-
27
- ### CDN
28
-
29
- Add the following script to your HTML:
30
-
31
- ```sh
32
- <script src="https://repo.incognia.com/web/latest/incognia-web-sdk.js"></script>
33
- ```
34
-
35
- ###
36
-
37
- ## Getting started
38
-
39
- Import the package:
40
-
41
- ```js
42
- // ES6
43
- import IncogniaWebSdk from '@incognia/web-sdk'
44
-
45
- // CommonJS (Outdated)
46
- const IncogniaWebSdk = require('@incognia/web-sdk')
47
-
48
- // CDN Script
49
- const IncogniaWebSdk = window.IncogniaWebSdk
50
- ```
51
-
52
- ## Library API methods
53
-
54
- ### Init
55
-
56
- Initialize the Web SDK with your Web Application ID. This step is _required_, and further methods will not work if the SDK is not initialized.
57
-
58
- ```js
59
- IncogniaWebSdk.init('<your-web-app-id>')
60
- ```
61
-
62
- ### Account ID
63
-
64
- The method `setAccountId` receives an account ID and stores locally. It is then added to the `requestToken` data.
65
-
66
- ```js
67
- IncogniaWebSdk.setAccountId('@accountId')
68
- ```
69
-
70
- The method `clearAccountId` removes the account ID from the local storage.
71
-
72
- ```js
73
- IncogniaWebSdk.clearAccountId()
74
- ```
75
-
76
- ### Generate request token
77
-
78
- This method generates a request token and returns it.
79
-
80
- ```js
81
- const requestToken = await IncogniaWebSdk.generateRequestToken()
82
- ```
83
-
84
- ### Send custom event
85
-
86
- This method sends a custom event with the client custom data.
87
-
88
- ```js
89
- IncogniaWebSdk.sendCustomEvent({
90
- tag: 'test-event',
91
- externalId: 'external-id',
92
- accountId: 'account-id',
93
- address: {
94
- street: 'Main Street',
95
- number: '100',
96
- city: 'New York',
97
- state: 'NY',
98
- countryName: 'US',
99
- postalCode: '10001',
100
- addressLine: 'Main Street 100, New York, NY, US, 10001',
101
- latitude: 40.7486,
102
- longitude: -73.9864
103
- },
104
- properties: {
105
- string: 'string',
106
- number: 123,
107
- boolean: false
108
- }
109
- })
110
- ```
111
-
112
- ## Geolocation API
113
-
114
- By default, the Incognia Web SDK does not ask the user for geolocation, because:
115
-
116
- - Not all use cases requires geolocation
117
- - The website should have total control when to ask for geolocation
118
- - The lib should run silently.
119
-
120
- However, if the geolocation is available (It was authorized by the user before), the Web SDK will include the geolocation information into the token.
121
-
122
- ### Allowing Incognia to request geolocation permissions
123
-
124
- When getting the `requestToken`, the option parameter `askForGeolocation` can be used to allow Incognia to automatically request the user location permissions.
125
-
126
- ```js
127
- const requestToken = await IncogniaWebSdk.generateRequestToken({
128
- askForGeolocation: true
129
- })
130
- ```
131
-
132
- ### How and when to ask the user for geolocation?
133
-
134
- The ideal flow to manually ask the user for geolocation is:
135
-
136
- 1. Initialize the SDK:
137
-
138
- ```js
139
- IncogniaWebSdk.init(...)
140
- ```
141
-
142
- 2. Ask the user for Geolocation and then proceed to get the token:
143
-
144
- ```js
145
- navigator.geolocation.getCurrentPosition(generateRequestToken, generateRequestToken)
146
-
147
- function generateRequestToken() {
148
- const requestToken = await IncogniaWebSdk.generateRequestToken()
149
- //TODO: Send the requestToken to your backend.
150
- }
151
- ```
152
-
153
- ## Browser Compatibility
154
-
155
- Except for IE, this lib is compatible with every modern browser.
156
-
157
- However, for Geolocation API, each browser handles it differently. For example, Firefox v104 does not provide the Geolocation API by default. So the user has to enable it.
158
- Besides, for some OSs like MacOS, you have to allow the browser to access the geolocation. If the geolocation is not available, the token will be generated without that information.
7
+ [logo]: https://www.incognia.com/hubfs/US/Brand/Logo/logo-incognia-purple.svg
8
+ [docs]: https://developer.incognia.com/docs/web/v1