@encorekit/web-sdk 0.1.1 → 0.1.7

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.
Files changed (134) hide show
  1. package/README.md +94 -9
  2. package/dist/cjs/index.cjs +1 -1
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/esm/index.js +1 -1
  5. package/dist/esm/index.js.map +1 -1
  6. package/dist/umd/encore.min.js +1 -1
  7. package/dist/umd/encore.min.js.map +1 -1
  8. package/embed/README.md +409 -0
  9. package/embed/index.html +57 -0
  10. package/embed/styles.css +154 -0
  11. package/examples/README.md +149 -0
  12. package/examples/angular/README.md +210 -0
  13. package/examples/angular/angular.json +73 -0
  14. package/examples/angular/package.json +32 -0
  15. package/examples/angular/src/app/app.component.html +56 -0
  16. package/examples/angular/src/app/app.component.ts +114 -0
  17. package/examples/angular/src/app/encore.service.ts +83 -0
  18. package/examples/angular/src/index.html +13 -0
  19. package/examples/angular/src/main.ts +7 -0
  20. package/examples/angular/src/styles.css +225 -0
  21. package/examples/angular/tsconfig.json +33 -0
  22. package/examples/ios-webview/EncoreURLBuilder.swift +87 -0
  23. package/examples/ios-webview/EncoreWebViewBridge.swift +426 -0
  24. package/examples/ios-webview/ExampleViewController.swift +233 -0
  25. package/examples/ios-webview/README.md +416 -0
  26. package/examples/ios-webview/SimpleEncoreView.swift +94 -0
  27. package/examples/ios-webview/SimpleExample.swift +131 -0
  28. package/examples/react/README.md +186 -0
  29. package/examples/react/index.html +13 -0
  30. package/examples/react/package.json +24 -0
  31. package/examples/react/src/App.tsx +173 -0
  32. package/examples/react/src/index.css +227 -0
  33. package/examples/react/src/main.tsx +11 -0
  34. package/examples/react/src/vite-env.d.ts +2 -0
  35. package/examples/react/tsconfig.json +25 -0
  36. package/examples/react/vite.config.ts +8 -0
  37. package/examples/svelte/README.md +233 -0
  38. package/examples/svelte/index.html +13 -0
  39. package/examples/svelte/package.json +25 -0
  40. package/examples/svelte/src/App.svelte +164 -0
  41. package/examples/svelte/src/app.css +224 -0
  42. package/examples/svelte/src/main.ts +9 -0
  43. package/examples/svelte/src/vite-env.d.ts +3 -0
  44. package/examples/svelte/svelte.config.js +8 -0
  45. package/examples/svelte/tsconfig.json +16 -0
  46. package/examples/svelte/tsconfig.node.json +11 -0
  47. package/examples/svelte/vite.config.ts +8 -0
  48. package/examples/vanilla-js/README.md +271 -0
  49. package/examples/vanilla-js/index.html +421 -0
  50. package/examples/vue/README.md +212 -0
  51. package/examples/vue/index.html +13 -0
  52. package/examples/vue/package.json +22 -0
  53. package/examples/vue/src/App.vue +170 -0
  54. package/examples/vue/src/main.ts +6 -0
  55. package/examples/vue/src/style.css +224 -0
  56. package/examples/vue/src/vite-env.d.ts +2 -0
  57. package/examples/vue/tsconfig.json +25 -0
  58. package/examples/vue/vite.config.ts +8 -0
  59. package/package.json +22 -3
  60. package/types/analytics/AnalyticsClient.d.ts +14 -0
  61. package/types/analytics/AnalyticsClient.d.ts.map +1 -0
  62. package/types/analytics/events.d.ts +63 -0
  63. package/types/analytics/events.d.ts.map +1 -0
  64. package/types/analytics/models.d.ts +17 -0
  65. package/types/analytics/models.d.ts.map +1 -0
  66. package/types/api/APIClient.d.ts +44 -8
  67. package/types/api/APIClient.d.ts.map +1 -1
  68. package/types/api/endpoints.d.ts +11 -7
  69. package/types/api/endpoints.d.ts.map +1 -1
  70. package/types/api/models.d.ts +134 -68
  71. package/types/api/models.d.ts.map +1 -1
  72. package/types/core/Configuration.d.ts +4 -0
  73. package/types/core/Configuration.d.ts.map +1 -1
  74. package/types/core/Encore.d.ts +16 -12
  75. package/types/core/Encore.d.ts.map +1 -1
  76. package/types/core/EntitlementManager.d.ts +9 -0
  77. package/types/core/EntitlementManager.d.ts.map +1 -1
  78. package/types/core/OfferManager.d.ts +27 -7
  79. package/types/core/OfferManager.d.ts.map +1 -1
  80. package/types/types.d.ts +1 -1
  81. package/types/types.d.ts.map +1 -1
  82. package/types/ui/OfferCard.d.ts.map +1 -1
  83. package/types/ui/OfferCarousel.d.ts.map +1 -1
  84. package/types/ui/Tooltip.d.ts +22 -0
  85. package/types/ui/Tooltip.d.ts.map +1 -0
  86. package/types/ui/styles.d.ts.map +1 -1
  87. package/dist/cjs/index.js +0 -2
  88. package/dist/cjs/index.js.map +0 -1
  89. package/types/src/api/APIClient.d.ts +0 -63
  90. package/types/src/api/APIClient.d.ts.map +0 -1
  91. package/types/src/api/endpoints.d.ts +0 -35
  92. package/types/src/api/endpoints.d.ts.map +0 -1
  93. package/types/src/api/models.d.ts +0 -156
  94. package/types/src/api/models.d.ts.map +0 -1
  95. package/types/src/core/Configuration.d.ts +0 -42
  96. package/types/src/core/Configuration.d.ts.map +0 -1
  97. package/types/src/core/Encore.d.ts +0 -81
  98. package/types/src/core/Encore.d.ts.map +0 -1
  99. package/types/src/core/EntitlementManager.d.ts +0 -65
  100. package/types/src/core/EntitlementManager.d.ts.map +0 -1
  101. package/types/src/core/OfferManager.d.ts +0 -35
  102. package/types/src/core/OfferManager.d.ts.map +0 -1
  103. package/types/src/core/PlacementBuilder.d.ts +0 -27
  104. package/types/src/core/PlacementBuilder.d.ts.map +0 -1
  105. package/types/src/core/SignalManager.d.ts +0 -51
  106. package/types/src/core/SignalManager.d.ts.map +0 -1
  107. package/types/src/core/StorageManager.d.ts +0 -34
  108. package/types/src/core/StorageManager.d.ts.map +0 -1
  109. package/types/src/core/VerificationPoller.d.ts +0 -27
  110. package/types/src/core/VerificationPoller.d.ts.map +0 -1
  111. package/types/src/index.d.ts +0 -7
  112. package/types/src/index.d.ts.map +0 -1
  113. package/types/src/types.d.ts +0 -156
  114. package/types/src/types.d.ts.map +0 -1
  115. package/types/src/ui/OfferCard.d.ts +0 -29
  116. package/types/src/ui/OfferCard.d.ts.map +0 -1
  117. package/types/src/ui/OfferCarousel.d.ts +0 -55
  118. package/types/src/ui/OfferCarousel.d.ts.map +0 -1
  119. package/types/src/ui/OfferModal.d.ts +0 -41
  120. package/types/src/ui/OfferModal.d.ts.map +0 -1
  121. package/types/src/ui/SuccessScreen.d.ts +0 -33
  122. package/types/src/ui/SuccessScreen.d.ts.map +0 -1
  123. package/types/src/ui/styles.d.ts +0 -44
  124. package/types/src/ui/styles.d.ts.map +0 -1
  125. package/types/src/utils/eventEmitter.d.ts +0 -50
  126. package/types/src/utils/eventEmitter.d.ts.map +0 -1
  127. package/types/src/utils/focusDetection.d.ts +0 -21
  128. package/types/src/utils/focusDetection.d.ts.map +0 -1
  129. package/types/src/utils/logger.d.ts +0 -21
  130. package/types/src/utils/logger.d.ts.map +0 -1
  131. package/types/src/utils/network.d.ts +0 -57
  132. package/types/src/utils/network.d.ts.map +0 -1
  133. package/types/src/utils/uuid.d.ts +0 -10
  134. package/types/src/utils/uuid.d.ts.map +0 -1
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from 'vite'
2
+ import { svelte } from '@sveltejs/vite-plugin-svelte'
3
+
4
+ // https://vitejs.dev/config/
5
+ export default defineConfig({
6
+ plugins: [svelte()],
7
+ })
8
+
@@ -0,0 +1,271 @@
1
+ # Encore SDK - Vanilla JavaScript Example
2
+
3
+ This example demonstrates how to integrate the Encore Web SDK into a plain HTML/JavaScript application using a CDN. No build tools or package managers required!
4
+
5
+ ## 🚀 Quick Start
6
+
7
+ Simply open `index.html` in your web browser:
8
+
9
+ ```bash
10
+ # macOS
11
+ open index.html
12
+
13
+ # Linux
14
+ xdg-open index.html
15
+
16
+ # Windows
17
+ start index.html
18
+ ```
19
+
20
+ Or serve it with a local web server:
21
+
22
+ ```bash
23
+ # Using Python
24
+ python -m http.server 8000
25
+
26
+ # Using Node.js http-server
27
+ npx http-server
28
+
29
+ # Using PHP
30
+ php -S localhost:8000
31
+ ```
32
+
33
+ Then visit `http://localhost:8000`
34
+
35
+ ## 📁 Project Structure
36
+
37
+ ```
38
+ vanilla-js/
39
+ ├── index.html # Complete standalone HTML file with embedded JavaScript
40
+ └── README.md # This file
41
+ ```
42
+
43
+ ## 🔑 Configuration
44
+
45
+ Before running the example, replace `'YOUR_API_KEY_HERE'` in `index.html` with your actual Encore API key:
46
+
47
+ ```javascript
48
+ Encore.configure({
49
+ apiKey: 'YOUR_API_KEY_HERE', // Get this from dashboard.encorekit.com
50
+ environment: 'production',
51
+ logLevel: 'debug',
52
+ })
53
+ ```
54
+
55
+ Find this line around line 271 in the `index.html` file.
56
+
57
+ ## 🎯 Features Demonstrated
58
+
59
+ ### 1. Loading SDK from CDN
60
+ The SDK is loaded via a script tag in the HTML:
61
+
62
+ ```html
63
+ <script src="https://encorekit.com/encore.min.js"></script>
64
+ ```
65
+
66
+ ### 2. SDK Initialization
67
+ Initialize the SDK when the page loads:
68
+
69
+ ```javascript
70
+ document.addEventListener('DOMContentLoaded', function() {
71
+ Encore.configure({
72
+ apiKey: 'YOUR_API_KEY_HERE',
73
+ environment: 'production',
74
+ logLevel: 'debug',
75
+ });
76
+
77
+ const currentUserId = Encore.getCurrentUserId();
78
+ // Update UI with user ID
79
+ });
80
+ ```
81
+
82
+ ### 3. DOM Manipulation
83
+ Direct DOM manipulation for UI updates:
84
+
85
+ ```javascript
86
+ const userId = document.getElementById('userId');
87
+ userId.textContent = currentUserId;
88
+ ```
89
+
90
+ ### 4. Event Listeners
91
+ Attach event listeners to buttons:
92
+
93
+ ```javascript
94
+ const identifyBtn = document.getElementById('identifyBtn');
95
+ identifyBtn.addEventListener('click', handleIdentifyUser);
96
+ ```
97
+
98
+ ### 5. User Identification
99
+ Identify users with custom IDs:
100
+
101
+ ```javascript
102
+ function handleIdentifyUser() {
103
+ const customUserId = customUserIdInput.value.trim();
104
+ Encore.identify(customUserId, {
105
+ email: 'user@example.com',
106
+ });
107
+ }
108
+ ```
109
+
110
+ ### 6. Presenting Offers
111
+ Display targeted offers:
112
+
113
+ ```javascript
114
+ async function handlePresentOffer() {
115
+ const result = await Encore.presentOffer();
116
+
117
+ if (result.granted) {
118
+ console.log('Offer granted!');
119
+ }
120
+ }
121
+ ```
122
+
123
+ ## 🏗️ Vanilla JavaScript Patterns
124
+
125
+ This example demonstrates:
126
+
127
+ - **No Build Tools** - Works directly in the browser
128
+ - **CDN Loading** - Load SDK from unpkg CDN
129
+ - **DOM Ready** - Wait for DOM before initializing
130
+ - **Event Delegation** - Proper event listener attachment
131
+ - **Async/Await** - Modern JavaScript async patterns
132
+ - **Error Handling** - Try-catch blocks for SDK operations
133
+
134
+ ## 📦 No Dependencies Required
135
+
136
+ This example has zero dependencies! Everything you need is:
137
+ - A web browser
138
+ - The `index.html` file
139
+ - An internet connection (to load the SDK from CDN)
140
+
141
+ ## 🔧 CDN Options
142
+
143
+ You can load the SDK from different CDNs:
144
+
145
+ ### unpkg (Recommended)
146
+ ```html
147
+ <script src="https://encorekit.com/encore.min.js"></script>
148
+ ```
149
+
150
+ ### jsDelivr
151
+ ```html
152
+ <script src="https://encorekit.com/encore.min.js"></script>
153
+ ```
154
+
155
+ ### Specific Version
156
+ Lock to a specific version for production:
157
+ ```html
158
+ <script src="https://encorekit.com/encore.min.js"></script>
159
+ ```
160
+
161
+ ## 💡 Best Practices
162
+
163
+ 1. **Load SDK Before Your Code** - Place the SDK script tag before your application code
164
+ 2. **Wait for DOM Ready** - Use `DOMContentLoaded` event to initialize
165
+ 3. **Version Pinning** - In production, use a specific version instead of `@latest`
166
+ 4. **Error Handling** - Always wrap SDK calls in try-catch blocks
167
+ 5. **HTTPS Only** - Serve your site over HTTPS in production
168
+ 6. **API Key Security** - Don't commit your API key to version control
169
+
170
+ ## 🎨 Customization
171
+
172
+ ### Using Environment Detection
173
+
174
+ For different API keys based on environment:
175
+
176
+ ```javascript
177
+ function getApiKey() {
178
+ const hostname = window.location.hostname;
179
+
180
+ if (hostname === 'localhost' || hostname === '127.0.0.1') {
181
+ return 'dev-api-key';
182
+ } else {
183
+ return 'prod-api-key';
184
+ }
185
+ }
186
+
187
+ Encore.configure({
188
+ apiKey: getApiKey(),
189
+ environment: 'production',
190
+ });
191
+ ```
192
+
193
+ ### Adding Custom Styling
194
+
195
+ The example includes embedded CSS in the `<style>` tag. You can:
196
+ - Extract styles to a separate CSS file
197
+ - Use your own CSS framework (Bootstrap, Tailwind, etc.)
198
+ - Customize colors and branding
199
+
200
+ ### Using Module Pattern
201
+
202
+ For better code organization:
203
+
204
+ ```javascript
205
+ const EncoreApp = (function() {
206
+ let isInitialized = false;
207
+
208
+ function initialize() {
209
+ Encore.configure({
210
+ apiKey: 'YOUR_API_KEY_HERE',
211
+ });
212
+ isInitialized = true;
213
+ }
214
+
215
+ async function presentOffer() {
216
+ if (!isInitialized) {
217
+ throw new Error('SDK not initialized');
218
+ }
219
+ return await Encore.presentOffer();
220
+ }
221
+
222
+ return {
223
+ initialize,
224
+ presentOffer,
225
+ };
226
+ })();
227
+
228
+ // Usage
229
+ EncoreApp.initialize();
230
+ await EncoreApp.presentOffer();
231
+ ```
232
+
233
+ ## 🌐 Browser Support
234
+
235
+ This example works in all modern browsers that support:
236
+ - ES6+ JavaScript (async/await, arrow functions, etc.)
237
+ - Promise API
238
+ - Fetch API
239
+
240
+ Supported browsers:
241
+ - Chrome/Edge 60+
242
+ - Firefox 60+
243
+ - Safari 12+
244
+ - iOS Safari 12+
245
+
246
+ ## 📚 Learn More
247
+
248
+ - [Encore SDK Documentation](https://docs.encorekit.com)
249
+ - [MDN Web Docs](https://developer.mozilla.org)
250
+ - [unpkg Documentation](https://unpkg.com)
251
+
252
+ ## 🆘 Support
253
+
254
+ - 📧 Email: admin@encorekit.com
255
+ - 📖 Docs: https://docs.encorekit.com
256
+
257
+
258
+ ## 💡 Tips
259
+
260
+ ### Debugging
261
+ Open browser console (F12) to see SDK logs when `logLevel: 'debug'` is set.
262
+
263
+ ### CORS Issues
264
+ If you're testing locally and encounter CORS issues, use a local web server instead of opening the file directly.
265
+
266
+ ### Testing Different Users
267
+ Change the user ID in the input field and click "Identify User" to test different user scenarios.
268
+
269
+ ### Offer Targeting
270
+ Make sure you have active offer campaigns in your Encore dashboard with appropriate targeting rules.
271
+
@@ -0,0 +1,421 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Encore SDK - Vanilla JavaScript Example</title>
7
+ <style>
8
+ :root {
9
+ font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
10
+ line-height: 1.5;
11
+ font-weight: 400;
12
+
13
+ color-scheme: light dark;
14
+ color: rgba(255, 255, 255, 0.87);
15
+ background-color: #242424;
16
+
17
+ font-synthesis: none;
18
+ text-rendering: optimizeLegibility;
19
+ -webkit-font-smoothing: antialiased;
20
+ -moz-osx-font-smoothing: grayscale;
21
+ }
22
+
23
+ * {
24
+ margin: 0;
25
+ padding: 0;
26
+ box-sizing: border-box;
27
+ }
28
+
29
+ body {
30
+ margin: 0;
31
+ display: flex;
32
+ place-items: center;
33
+ min-width: 320px;
34
+ min-height: 100vh;
35
+ }
36
+
37
+ #app {
38
+ width: 100%;
39
+ max-width: 1280px;
40
+ margin: 0 auto;
41
+ padding: 2rem;
42
+ text-align: center;
43
+ }
44
+
45
+ h1 {
46
+ font-size: 3.2em;
47
+ line-height: 1.1;
48
+ margin-bottom: 1rem;
49
+ }
50
+
51
+ h2 {
52
+ font-size: 1.8em;
53
+ margin-top: 2rem;
54
+ margin-bottom: 1rem;
55
+ }
56
+
57
+ .card {
58
+ padding: 2em;
59
+ background-color: #1a1a1a;
60
+ border-radius: 8px;
61
+ margin-bottom: 2rem;
62
+ }
63
+
64
+ .user-info {
65
+ margin: 1.5rem 0;
66
+ padding: 1rem;
67
+ background-color: #2a2a2a;
68
+ border-radius: 4px;
69
+ font-family: monospace;
70
+ }
71
+
72
+ .user-info strong {
73
+ color: #f0db4f;
74
+ }
75
+
76
+ .button-group {
77
+ display: flex;
78
+ gap: 1rem;
79
+ justify-content: center;
80
+ flex-wrap: wrap;
81
+ margin: 1.5rem 0;
82
+ }
83
+
84
+ button {
85
+ border-radius: 8px;
86
+ border: 1px solid transparent;
87
+ padding: 0.6em 1.2em;
88
+ font-size: 1em;
89
+ font-weight: 500;
90
+ font-family: inherit;
91
+ background-color: #1a1a1a;
92
+ cursor: pointer;
93
+ transition: border-color 0.25s;
94
+ }
95
+
96
+ button:hover {
97
+ border-color: #f0db4f;
98
+ }
99
+
100
+ button:focus,
101
+ button:focus-visible {
102
+ outline: 4px auto -webkit-focus-ring-color;
103
+ }
104
+
105
+ button:disabled {
106
+ opacity: 0.5;
107
+ cursor: not-allowed;
108
+ }
109
+
110
+ button:disabled:hover {
111
+ border-color: transparent;
112
+ }
113
+
114
+ .primary {
115
+ background-color: #f0db4f;
116
+ color: #323330;
117
+ }
118
+
119
+ .primary:hover {
120
+ background-color: #e5d049;
121
+ border-color: #e5d049;
122
+ }
123
+
124
+ .success {
125
+ background-color: #059669;
126
+ color: white;
127
+ }
128
+
129
+ .success:hover {
130
+ background-color: #047857;
131
+ border-color: #047857;
132
+ }
133
+
134
+ .status {
135
+ margin: 1rem 0;
136
+ padding: 0.8rem;
137
+ border-radius: 4px;
138
+ font-size: 0.9em;
139
+ display: none;
140
+ }
141
+
142
+ .status.visible {
143
+ display: block;
144
+ }
145
+
146
+ .status.info {
147
+ background-color: #1e40af;
148
+ color: white;
149
+ }
150
+
151
+ .status.success {
152
+ background-color: #059669;
153
+ color: white;
154
+ }
155
+
156
+ .status.error {
157
+ background-color: #dc2626;
158
+ color: white;
159
+ }
160
+
161
+ .input-group {
162
+ margin: 1rem 0;
163
+ text-align: left;
164
+ }
165
+
166
+ .input-group label {
167
+ display: block;
168
+ margin-bottom: 0.5rem;
169
+ font-weight: 500;
170
+ }
171
+
172
+ .input-group input {
173
+ width: 100%;
174
+ padding: 0.6em;
175
+ border-radius: 4px;
176
+ border: 1px solid #444;
177
+ background-color: #1a1a1a;
178
+ color: inherit;
179
+ font-size: 1em;
180
+ font-family: inherit;
181
+ }
182
+
183
+ .input-group input:focus {
184
+ outline: 2px solid #f0db4f;
185
+ border-color: #f0db4f;
186
+ }
187
+
188
+ code {
189
+ background-color: #2a2a2a;
190
+ padding: 0.2em 0.4em;
191
+ border-radius: 3px;
192
+ font-family: monospace;
193
+ font-size: 0.9em;
194
+ }
195
+
196
+ pre {
197
+ text-align: left;
198
+ background-color: #1a1a1a;
199
+ padding: 1rem;
200
+ border-radius: 4px;
201
+ overflow-x: auto;
202
+ margin: 1rem 0;
203
+ }
204
+
205
+ @media (prefers-color-scheme: light) {
206
+ :root {
207
+ color: #213547;
208
+ background-color: #ffffff;
209
+ }
210
+
211
+ button {
212
+ background-color: #f9f9f9;
213
+ }
214
+
215
+ .card {
216
+ background-color: #f9f9f9;
217
+ }
218
+
219
+ .user-info {
220
+ background-color: #efefef;
221
+ }
222
+
223
+ .input-group input {
224
+ background-color: #ffffff;
225
+ border-color: #ccc;
226
+ }
227
+
228
+ code {
229
+ background-color: #efefef;
230
+ }
231
+
232
+ pre {
233
+ background-color: #f5f5f5;
234
+ }
235
+ }
236
+ </style>
237
+ </head>
238
+ <body>
239
+ <div id="app">
240
+ <h1>🎯 Encore SDK</h1>
241
+ <p>Vanilla JavaScript Example</p>
242
+
243
+ <div class="card">
244
+ <h2>SDK Status</h2>
245
+ <div class="user-info">
246
+ <strong>Status:</strong> <span id="sdkStatus">Not Initialized</span>
247
+ <br />
248
+ <strong>User ID:</strong> <span id="userId">Not set</span>
249
+ </div>
250
+
251
+ <div id="status" class="status"></div>
252
+ </div>
253
+
254
+ <div class="card">
255
+ <h2>User Identification</h2>
256
+ <div class="input-group">
257
+ <label for="customUserId">Custom User ID:</label>
258
+ <input
259
+ id="customUserId"
260
+ type="text"
261
+ placeholder="Enter user ID (e.g., user-123)"
262
+ disabled
263
+ />
264
+ </div>
265
+ <button id="identifyBtn" class="primary" disabled>
266
+ Identify User
267
+ </button>
268
+ </div>
269
+
270
+ <div class="card">
271
+ <h2>Present Offer</h2>
272
+ <p>Click the button below to display an offer to the user.</p>
273
+ <button id="presentOfferBtn" class="success" disabled>
274
+ 🎁 Present Offer
275
+ </button>
276
+ </div>
277
+
278
+ <div class="card">
279
+ <h2>Code Example</h2>
280
+ <pre>// Load SDK via CDN
281
+ &lt;script src="https://encorekit.com/encore.min.js"&gt;&lt;/script&gt;
282
+
283
+ // Get SDK instance (UMD export uses .default)
284
+ const EncoreSDK = Encore.default || Encore;
285
+
286
+ // Initialize SDK
287
+ EncoreSDK.configure({
288
+ apiKey: 'your-api-key',
289
+ userId: 'user-123',
290
+ environment: 'production',
291
+ })
292
+
293
+ // Identify user
294
+ EncoreSDK.identify('user-123', {
295
+ email: 'user@example.com'
296
+ })
297
+
298
+ // Present offer
299
+ const result = await EncoreSDK.presentOffer()
300
+ if (result.granted) {
301
+ console.log('Offer granted!')
302
+ }</pre>
303
+ </div>
304
+ </div>
305
+
306
+ <!-- Load Encore SDK from CDN -->
307
+ <script src="https://encorekit.com/encore.min.js"></script>
308
+
309
+ <script>
310
+ // Wait for DOM to be ready
311
+ document.addEventListener('DOMContentLoaded', function() {
312
+ // Get DOM elements
313
+ const sdkStatus = document.getElementById('sdkStatus');
314
+ const userId = document.getElementById('userId');
315
+ const statusDiv = document.getElementById('status');
316
+ const customUserIdInput = document.getElementById('customUserId');
317
+ const identifyBtn = document.getElementById('identifyBtn');
318
+ const presentOfferBtn = document.getElementById('presentOfferBtn');
319
+
320
+ let isInitialized = false;
321
+
322
+ // Helper function to show status messages
323
+ function showStatus(message, type) {
324
+ statusDiv.textContent = message;
325
+ statusDiv.className = 'status visible ' + type;
326
+
327
+ // Auto-hide after 5 seconds for success messages
328
+ if (type === 'success' || type === 'info') {
329
+ setTimeout(function() {
330
+ statusDiv.classList.remove('visible');
331
+ }, 5000);
332
+ }
333
+ }
334
+
335
+ // Initialize SDK
336
+ function initializeSDK() {
337
+ try {
338
+ // Check if Encore SDK is loaded
339
+ if (typeof Encore === 'undefined') {
340
+ throw new Error('Encore SDK not loaded');
341
+ }
342
+
343
+ // Get the SDK instance (UMD export uses .default)
344
+ var EncoreSDK = Encore.default || Encore;
345
+
346
+ // Configure the SDK
347
+ EncoreSDK.configure({
348
+ apiKey: 'ENCORE_PUBLIC_API_KEY', // Replace with your actual API key
349
+ userId: 'test-vanilla-js',
350
+ environment: 'production',
351
+ logLevel: 'debug',
352
+ });
353
+
354
+ // Get current user ID
355
+ const currentUserId = EncoreSDK.getCurrentUserId();
356
+ userId.textContent = currentUserId || 'Not set';
357
+
358
+ // Update UI
359
+ isInitialized = true;
360
+ sdkStatus.textContent = '✓ Initialized';
361
+ customUserIdInput.disabled = false;
362
+ identifyBtn.disabled = false;
363
+ presentOfferBtn.disabled = false;
364
+
365
+ showStatus('Encore SDK initialized successfully!', 'success');
366
+ } catch (error) {
367
+ showStatus('Failed to initialize SDK: ' + error.message, 'error');
368
+ }
369
+ }
370
+
371
+ // Identify user
372
+ function handleIdentifyUser() {
373
+ const customUserId = customUserIdInput.value.trim();
374
+
375
+ if (!customUserId) {
376
+ showStatus('Please enter a user ID', 'error');
377
+ return;
378
+ }
379
+
380
+ try {
381
+ var EncoreSDK = Encore.default || Encore;
382
+ EncoreSDK.identify(customUserId, {
383
+ email: 'user@example.com',
384
+ });
385
+
386
+ userId.textContent = customUserId;
387
+ showStatus('User identified as: ' + customUserId, 'success');
388
+ } catch (error) {
389
+ showStatus('Failed to identify user: ' + error.message, 'error');
390
+ }
391
+ }
392
+
393
+ // Present offer
394
+ async function handlePresentOffer() {
395
+ showStatus('Presenting offer...', 'info');
396
+
397
+ try {
398
+ var EncoreSDK = Encore.default || Encore;
399
+ const result = await EncoreSDK.presentOffer();
400
+
401
+ if (result.granted) {
402
+ showStatus('Offer granted successfully!', 'success');
403
+ } else {
404
+ showStatus('Offer not granted: ' + JSON.stringify(result.reason), 'info');
405
+ }
406
+ } catch (error) {
407
+ showStatus('Failed to present offer: ' + error.message, 'error');
408
+ }
409
+ }
410
+
411
+ // Attach event listeners
412
+ identifyBtn.addEventListener('click', handleIdentifyUser);
413
+ presentOfferBtn.addEventListener('click', handlePresentOffer);
414
+
415
+ // Initialize SDK when page loads
416
+ initializeSDK();
417
+ });
418
+ </script>
419
+ </body>
420
+ </html>
421
+