@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.
- package/README.md +94 -9
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/umd/encore.min.js +1 -1
- package/dist/umd/encore.min.js.map +1 -1
- package/embed/README.md +409 -0
- package/embed/index.html +57 -0
- package/embed/styles.css +154 -0
- package/examples/README.md +149 -0
- package/examples/angular/README.md +210 -0
- package/examples/angular/angular.json +73 -0
- package/examples/angular/package.json +32 -0
- package/examples/angular/src/app/app.component.html +56 -0
- package/examples/angular/src/app/app.component.ts +114 -0
- package/examples/angular/src/app/encore.service.ts +83 -0
- package/examples/angular/src/index.html +13 -0
- package/examples/angular/src/main.ts +7 -0
- package/examples/angular/src/styles.css +225 -0
- package/examples/angular/tsconfig.json +33 -0
- package/examples/ios-webview/EncoreURLBuilder.swift +87 -0
- package/examples/ios-webview/EncoreWebViewBridge.swift +426 -0
- package/examples/ios-webview/ExampleViewController.swift +233 -0
- package/examples/ios-webview/README.md +416 -0
- package/examples/ios-webview/SimpleEncoreView.swift +94 -0
- package/examples/ios-webview/SimpleExample.swift +131 -0
- package/examples/react/README.md +186 -0
- package/examples/react/index.html +13 -0
- package/examples/react/package.json +24 -0
- package/examples/react/src/App.tsx +173 -0
- package/examples/react/src/index.css +227 -0
- package/examples/react/src/main.tsx +11 -0
- package/examples/react/src/vite-env.d.ts +2 -0
- package/examples/react/tsconfig.json +25 -0
- package/examples/react/vite.config.ts +8 -0
- package/examples/svelte/README.md +233 -0
- package/examples/svelte/index.html +13 -0
- package/examples/svelte/package.json +25 -0
- package/examples/svelte/src/App.svelte +164 -0
- package/examples/svelte/src/app.css +224 -0
- package/examples/svelte/src/main.ts +9 -0
- package/examples/svelte/src/vite-env.d.ts +3 -0
- package/examples/svelte/svelte.config.js +8 -0
- package/examples/svelte/tsconfig.json +16 -0
- package/examples/svelte/tsconfig.node.json +11 -0
- package/examples/svelte/vite.config.ts +8 -0
- package/examples/vanilla-js/README.md +271 -0
- package/examples/vanilla-js/index.html +421 -0
- package/examples/vue/README.md +212 -0
- package/examples/vue/index.html +13 -0
- package/examples/vue/package.json +22 -0
- package/examples/vue/src/App.vue +170 -0
- package/examples/vue/src/main.ts +6 -0
- package/examples/vue/src/style.css +224 -0
- package/examples/vue/src/vite-env.d.ts +2 -0
- package/examples/vue/tsconfig.json +25 -0
- package/examples/vue/vite.config.ts +8 -0
- package/package.json +22 -3
- package/types/analytics/AnalyticsClient.d.ts +14 -0
- package/types/analytics/AnalyticsClient.d.ts.map +1 -0
- package/types/analytics/events.d.ts +63 -0
- package/types/analytics/events.d.ts.map +1 -0
- package/types/analytics/models.d.ts +17 -0
- package/types/analytics/models.d.ts.map +1 -0
- package/types/api/APIClient.d.ts +44 -8
- package/types/api/APIClient.d.ts.map +1 -1
- package/types/api/endpoints.d.ts +11 -7
- package/types/api/endpoints.d.ts.map +1 -1
- package/types/api/models.d.ts +134 -68
- package/types/api/models.d.ts.map +1 -1
- package/types/core/Configuration.d.ts +4 -0
- package/types/core/Configuration.d.ts.map +1 -1
- package/types/core/Encore.d.ts +16 -12
- package/types/core/Encore.d.ts.map +1 -1
- package/types/core/EntitlementManager.d.ts +9 -0
- package/types/core/EntitlementManager.d.ts.map +1 -1
- package/types/core/OfferManager.d.ts +27 -7
- package/types/core/OfferManager.d.ts.map +1 -1
- package/types/types.d.ts +1 -1
- package/types/types.d.ts.map +1 -1
- package/types/ui/OfferCard.d.ts.map +1 -1
- package/types/ui/OfferCarousel.d.ts.map +1 -1
- package/types/ui/Tooltip.d.ts +22 -0
- package/types/ui/Tooltip.d.ts.map +1 -0
- package/types/ui/styles.d.ts.map +1 -1
- package/dist/cjs/index.js +0 -2
- package/dist/cjs/index.js.map +0 -1
- package/types/src/api/APIClient.d.ts +0 -63
- package/types/src/api/APIClient.d.ts.map +0 -1
- package/types/src/api/endpoints.d.ts +0 -35
- package/types/src/api/endpoints.d.ts.map +0 -1
- package/types/src/api/models.d.ts +0 -156
- package/types/src/api/models.d.ts.map +0 -1
- package/types/src/core/Configuration.d.ts +0 -42
- package/types/src/core/Configuration.d.ts.map +0 -1
- package/types/src/core/Encore.d.ts +0 -81
- package/types/src/core/Encore.d.ts.map +0 -1
- package/types/src/core/EntitlementManager.d.ts +0 -65
- package/types/src/core/EntitlementManager.d.ts.map +0 -1
- package/types/src/core/OfferManager.d.ts +0 -35
- package/types/src/core/OfferManager.d.ts.map +0 -1
- package/types/src/core/PlacementBuilder.d.ts +0 -27
- package/types/src/core/PlacementBuilder.d.ts.map +0 -1
- package/types/src/core/SignalManager.d.ts +0 -51
- package/types/src/core/SignalManager.d.ts.map +0 -1
- package/types/src/core/StorageManager.d.ts +0 -34
- package/types/src/core/StorageManager.d.ts.map +0 -1
- package/types/src/core/VerificationPoller.d.ts +0 -27
- package/types/src/core/VerificationPoller.d.ts.map +0 -1
- package/types/src/index.d.ts +0 -7
- package/types/src/index.d.ts.map +0 -1
- package/types/src/types.d.ts +0 -156
- package/types/src/types.d.ts.map +0 -1
- package/types/src/ui/OfferCard.d.ts +0 -29
- package/types/src/ui/OfferCard.d.ts.map +0 -1
- package/types/src/ui/OfferCarousel.d.ts +0 -55
- package/types/src/ui/OfferCarousel.d.ts.map +0 -1
- package/types/src/ui/OfferModal.d.ts +0 -41
- package/types/src/ui/OfferModal.d.ts.map +0 -1
- package/types/src/ui/SuccessScreen.d.ts +0 -33
- package/types/src/ui/SuccessScreen.d.ts.map +0 -1
- package/types/src/ui/styles.d.ts +0 -44
- package/types/src/ui/styles.d.ts.map +0 -1
- package/types/src/utils/eventEmitter.d.ts +0 -50
- package/types/src/utils/eventEmitter.d.ts.map +0 -1
- package/types/src/utils/focusDetection.d.ts +0 -21
- package/types/src/utils/focusDetection.d.ts.map +0 -1
- package/types/src/utils/logger.d.ts +0 -21
- package/types/src/utils/logger.d.ts.map +0 -1
- package/types/src/utils/network.d.ts +0 -57
- package/types/src/utils/network.d.ts.map +0 -1
- package/types/src/utils/uuid.d.ts +0 -10
- package/types/src/utils/uuid.d.ts.map +0 -1
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# Encore Web SDK Examples
|
|
2
|
+
|
|
3
|
+
Welcome to the Encore Web SDK examples! This directory contains complete, standalone example projects demonstrating how to integrate the Encore SDK into various web frameworks.
|
|
4
|
+
|
|
5
|
+
## 📦 Available Examples
|
|
6
|
+
|
|
7
|
+
| Framework | Description | Build Tool | Package Manager |
|
|
8
|
+
|-----------|-------------|------------|-----------------|
|
|
9
|
+
| [React](./react) | React 18 + TypeScript with custom hook | Vite | npm |
|
|
10
|
+
| [Vue](./vue) | Vue 3 Composition API + TypeScript | Vite | npm |
|
|
11
|
+
| [Angular](./angular) | Angular 17+ standalone components | Angular CLI | npm |
|
|
12
|
+
| [Svelte](./svelte) | Svelte 4 + TypeScript | Vite | npm |
|
|
13
|
+
| [Vanilla JS](./vanilla-js) | Plain JavaScript with CDN | None | None |
|
|
14
|
+
|
|
15
|
+
## 🚀 Quick Start
|
|
16
|
+
|
|
17
|
+
Each example is self-contained and ready to run. Choose your preferred framework:
|
|
18
|
+
|
|
19
|
+
### React
|
|
20
|
+
```bash
|
|
21
|
+
cd react
|
|
22
|
+
npm install
|
|
23
|
+
npm run dev
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Vue
|
|
27
|
+
```bash
|
|
28
|
+
cd vue
|
|
29
|
+
npm install
|
|
30
|
+
npm run dev
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Angular
|
|
34
|
+
```bash
|
|
35
|
+
cd angular
|
|
36
|
+
npm install
|
|
37
|
+
npm start
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Svelte
|
|
41
|
+
```bash
|
|
42
|
+
cd svelte
|
|
43
|
+
npm install
|
|
44
|
+
npm run dev
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Vanilla JavaScript
|
|
48
|
+
```bash
|
|
49
|
+
cd vanilla-js
|
|
50
|
+
# Open index.html in your browser (no build step required)
|
|
51
|
+
open index.html
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 🎯 What Each Example Demonstrates
|
|
55
|
+
|
|
56
|
+
All examples show the core Encore SDK features:
|
|
57
|
+
|
|
58
|
+
1. **SDK Configuration** - Initialize the SDK with your API key
|
|
59
|
+
2. **User Identification** - Identify users with custom IDs and attributes
|
|
60
|
+
3. **Offer Presentation** - Display targeted offers to users
|
|
61
|
+
4. **State Management** - Track SDK state and user information
|
|
62
|
+
|
|
63
|
+
## 📋 Prerequisites
|
|
64
|
+
|
|
65
|
+
- Node.js 18+ (not required for vanilla-js example)
|
|
66
|
+
- npm or yarn
|
|
67
|
+
- An Encore API key (get one at [dashboard.encorekit.com](https://dashboard.encorekit.com))
|
|
68
|
+
|
|
69
|
+
## 🔑 Setup Your API Key
|
|
70
|
+
|
|
71
|
+
Before running any example, you'll need to configure your Encore API key:
|
|
72
|
+
|
|
73
|
+
1. Sign up at [dashboard.encorekit.com](https://dashboard.encorekit.com)
|
|
74
|
+
2. Create a new application
|
|
75
|
+
3. Copy your public API key
|
|
76
|
+
4. Replace `'YOUR_API_KEY_HERE'` in the example code with your actual key
|
|
77
|
+
|
|
78
|
+
## 🏗️ Framework-Specific Patterns
|
|
79
|
+
|
|
80
|
+
### React Pattern
|
|
81
|
+
Uses a custom `useEncore()` hook for SDK lifecycle management:
|
|
82
|
+
```typescript
|
|
83
|
+
const { userId, initialize, presentOffer } = useEncore();
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Vue Pattern
|
|
87
|
+
Uses a composable function with Vue's Composition API:
|
|
88
|
+
```typescript
|
|
89
|
+
const { userId, initialize, presentOffer } = useEncore();
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Angular Pattern
|
|
93
|
+
Uses a service with dependency injection:
|
|
94
|
+
```typescript
|
|
95
|
+
constructor(private encoreService: EncoreService) {}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Svelte Pattern
|
|
99
|
+
Uses reactive stores for state management:
|
|
100
|
+
```typescript
|
|
101
|
+
import { encoreStore } from './stores/encore';
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Vanilla JS Pattern
|
|
105
|
+
Direct SDK usage with DOM manipulation:
|
|
106
|
+
```javascript
|
|
107
|
+
Encore.configure({ apiKey: 'your-key' });
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 📚 Documentation
|
|
111
|
+
|
|
112
|
+
For complete SDK documentation, visit:
|
|
113
|
+
- [Full Documentation](https://docs.encorekit.com)
|
|
114
|
+
|
|
115
|
+
## 🔧 Troubleshooting
|
|
116
|
+
|
|
117
|
+
### "Module not found" errors
|
|
118
|
+
Make sure you've run `npm install` in the example directory.
|
|
119
|
+
|
|
120
|
+
### SDK not loading
|
|
121
|
+
Check that you've replaced `'YOUR_API_KEY_HERE'` with your actual API key.
|
|
122
|
+
|
|
123
|
+
### CORS errors
|
|
124
|
+
The Encore SDK is configured to work with CORS. If you see CORS errors, check your API key and environment settings.
|
|
125
|
+
|
|
126
|
+
### No offers available
|
|
127
|
+
Ensure you have:
|
|
128
|
+
1. Created at least one offer campaign in your dashboard
|
|
129
|
+
2. Set up targeting rules that match your user
|
|
130
|
+
3. Activated the campaign
|
|
131
|
+
|
|
132
|
+
## 💡 Best Practices
|
|
133
|
+
|
|
134
|
+
1. **Never commit API keys** - Use environment variables in production
|
|
135
|
+
2. **Server-side validation** - Always validate entitlements on your backend
|
|
136
|
+
3. **Error handling** - Wrap SDK calls in try-catch blocks
|
|
137
|
+
4. **User privacy** - Only collect necessary user attributes
|
|
138
|
+
5. **Testing** - Use test mode for development
|
|
139
|
+
|
|
140
|
+
## 🆘 Support
|
|
141
|
+
|
|
142
|
+
Need help? Reach out:
|
|
143
|
+
- 📧 Email: admin@encorekit.com
|
|
144
|
+
- 📖 Docs: https://docs.encorekit.com
|
|
145
|
+
|
|
146
|
+
## 📄 License
|
|
147
|
+
|
|
148
|
+
These examples are provided as-is for demonstration purposes. The Encore SDK itself is covered by its own license terms.
|
|
149
|
+
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# Encore SDK - Angular Example
|
|
2
|
+
|
|
3
|
+
This example demonstrates how to integrate the Encore Web SDK into an Angular 17+ application using standalone components and services.
|
|
4
|
+
|
|
5
|
+
## 🚀 Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install dependencies
|
|
9
|
+
npm install
|
|
10
|
+
|
|
11
|
+
# Start development server
|
|
12
|
+
npm start
|
|
13
|
+
|
|
14
|
+
# Build for production
|
|
15
|
+
npm run build
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The app will be available at `http://localhost:4200`
|
|
19
|
+
|
|
20
|
+
## 📁 Project Structure
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
angular/
|
|
24
|
+
├── src/
|
|
25
|
+
│ ├── app/
|
|
26
|
+
│ │ ├── app.component.ts # Main application component
|
|
27
|
+
│ │ ├── app.component.html # Component template
|
|
28
|
+
│ │ └── encore.service.ts # Encore SDK service
|
|
29
|
+
│ ├── main.ts # Application entry point
|
|
30
|
+
│ ├── styles.css # Global styles
|
|
31
|
+
│ └── index.html # HTML template
|
|
32
|
+
├── angular.json # Angular CLI configuration
|
|
33
|
+
├── package.json # Dependencies and scripts
|
|
34
|
+
└── tsconfig.json # TypeScript configuration
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 🔑 Configuration
|
|
38
|
+
|
|
39
|
+
Before running the example, replace `'YOUR_API_KEY_HERE'` in `src/app/app.component.ts` with your actual Encore API key:
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
this.encoreService.initialize('YOUR_API_KEY_HERE', 'production');
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 🎯 Features Demonstrated
|
|
46
|
+
|
|
47
|
+
### 1. Service-Based Architecture
|
|
48
|
+
The SDK is wrapped in an Angular service for better organization:
|
|
49
|
+
|
|
50
|
+
```typescript
|
|
51
|
+
@Injectable({
|
|
52
|
+
providedIn: 'root'
|
|
53
|
+
})
|
|
54
|
+
export class EncoreService {
|
|
55
|
+
initialize(apiKey: string): void {
|
|
56
|
+
Encore.configure({ apiKey });
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async presentOffer(): Promise<any> {
|
|
60
|
+
return await Encore.presentOffer();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 2. Dependency Injection
|
|
66
|
+
The service is injected into components:
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
constructor(private encoreService: EncoreService) {}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 3. Lifecycle Hooks
|
|
73
|
+
SDK initialization happens in `ngOnInit`:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
ngOnInit() {
|
|
77
|
+
this.encoreService.initialize('YOUR_API_KEY_HERE');
|
|
78
|
+
this.userId = this.encoreService.getCurrentUserId() || '';
|
|
79
|
+
this.isInitialized = true;
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### 4. Two-Way Data Binding
|
|
84
|
+
Angular's `[(ngModel)]` for form inputs:
|
|
85
|
+
|
|
86
|
+
```html
|
|
87
|
+
<input [(ngModel)]="customUserId" />
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### 5. Async Operations
|
|
91
|
+
Proper handling of async SDK methods:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
async handlePresentOffer() {
|
|
95
|
+
const result = await this.encoreService.presentOffer();
|
|
96
|
+
if (result.granted) {
|
|
97
|
+
console.log('Offer granted!');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 🏗️ Angular Patterns
|
|
103
|
+
|
|
104
|
+
This example uses Angular best practices:
|
|
105
|
+
|
|
106
|
+
- **Standalone Components** - Modern Angular 17+ approach
|
|
107
|
+
- **Services** - Separation of concerns with injectable services
|
|
108
|
+
- **Dependency Injection** - Angular's DI system
|
|
109
|
+
- **TypeScript** - Full type safety
|
|
110
|
+
- **Reactive Forms** - Two-way data binding with FormsModule
|
|
111
|
+
- **Template Syntax** - Angular's declarative templates
|
|
112
|
+
|
|
113
|
+
## 📦 Dependencies
|
|
114
|
+
|
|
115
|
+
- `@angular/core` ^17.3.0 - Angular framework
|
|
116
|
+
- `@angular/common` ^17.3.0 - Angular common utilities
|
|
117
|
+
- `@angular/platform-browser` ^17.3.0 - Browser platform
|
|
118
|
+
- `@encorekit/web-sdk` ^0.2.0 - Encore Web SDK
|
|
119
|
+
- `rxjs` ~7.8.0 - Reactive extensions
|
|
120
|
+
- `zone.js` ~0.14.3 - Zone execution context
|
|
121
|
+
|
|
122
|
+
## 🔧 Available Scripts
|
|
123
|
+
|
|
124
|
+
- `npm start` - Start development server (alias for `ng serve`)
|
|
125
|
+
- `npm run build` - Build for production
|
|
126
|
+
- `npm run watch` - Build and watch for changes
|
|
127
|
+
|
|
128
|
+
## 💡 Best Practices
|
|
129
|
+
|
|
130
|
+
1. **Service Layer** - Wrap the SDK in an Angular service
|
|
131
|
+
2. **Dependency Injection** - Use Angular's DI for service access
|
|
132
|
+
3. **Error Handling** - Always wrap SDK calls in try-catch blocks
|
|
133
|
+
4. **Type Safety** - Define interfaces for SDK responses
|
|
134
|
+
5. **Lifecycle Management** - Initialize in `ngOnInit`, cleanup if needed
|
|
135
|
+
6. **Environment Variables** - Use Angular's environment files for configuration
|
|
136
|
+
|
|
137
|
+
## 🎨 Customization
|
|
138
|
+
|
|
139
|
+
### Using Environment Files
|
|
140
|
+
|
|
141
|
+
Create `src/environments/environment.ts`:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
export const environment = {
|
|
145
|
+
production: false,
|
|
146
|
+
encoreApiKey: 'your-api-key-here',
|
|
147
|
+
};
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Create `src/environments/environment.prod.ts`:
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
export const environment = {
|
|
154
|
+
production: true,
|
|
155
|
+
encoreApiKey: 'your-production-api-key',
|
|
156
|
+
};
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
Update `app.component.ts`:
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
import { environment } from '../environments/environment';
|
|
163
|
+
|
|
164
|
+
ngOnInit() {
|
|
165
|
+
this.encoreService.initialize(environment.encoreApiKey);
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Using RxJS Observables
|
|
170
|
+
|
|
171
|
+
For better reactive patterns, you can enhance the service:
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
import { Injectable } from '@angular/core';
|
|
175
|
+
import { BehaviorSubject, Observable } from 'rxjs';
|
|
176
|
+
import Encore from '@encorekit/web-sdk';
|
|
177
|
+
|
|
178
|
+
@Injectable({
|
|
179
|
+
providedIn: 'root'
|
|
180
|
+
})
|
|
181
|
+
export class EncoreService {
|
|
182
|
+
private userIdSubject = new BehaviorSubject<string>('');
|
|
183
|
+
userId$: Observable<string> = this.userIdSubject.asObservable();
|
|
184
|
+
|
|
185
|
+
initialize(apiKey: string): void {
|
|
186
|
+
Encore.configure({ apiKey });
|
|
187
|
+
const userId = Encore.getCurrentUserId() || '';
|
|
188
|
+
this.userIdSubject.next(userId);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
identify(userId: string, attributes?: Record<string, any>): void {
|
|
192
|
+
Encore.identify(userId, attributes);
|
|
193
|
+
this.userIdSubject.next(userId);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
## 📚 Learn More
|
|
199
|
+
|
|
200
|
+
- [Encore SDK Documentation](https://docs.encorekit.com)
|
|
201
|
+
- [Angular Documentation](https://angular.io)
|
|
202
|
+
- [Angular CLI Documentation](https://angular.io/cli)
|
|
203
|
+
- [RxJS Documentation](https://rxjs.dev)
|
|
204
|
+
|
|
205
|
+
## 🆘 Support
|
|
206
|
+
|
|
207
|
+
- 📧 Email: admin@encorekit.com
|
|
208
|
+
- 📖 Docs: https://docs.encorekit.com
|
|
209
|
+
|
|
210
|
+
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
|
|
3
|
+
"version": 1,
|
|
4
|
+
"newProjectRoot": "projects",
|
|
5
|
+
"projects": {
|
|
6
|
+
"encore-sdk-angular-example": {
|
|
7
|
+
"projectType": "application",
|
|
8
|
+
"schematics": {
|
|
9
|
+
"@schematics/angular:component": {
|
|
10
|
+
"style": "css"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"root": "",
|
|
14
|
+
"sourceRoot": "src",
|
|
15
|
+
"prefix": "app",
|
|
16
|
+
"architect": {
|
|
17
|
+
"build": {
|
|
18
|
+
"builder": "@angular-devkit/build-angular:browser",
|
|
19
|
+
"options": {
|
|
20
|
+
"outputPath": "dist/encore-sdk-angular-example",
|
|
21
|
+
"index": "src/index.html",
|
|
22
|
+
"main": "src/main.ts",
|
|
23
|
+
"tsConfig": "tsconfig.json",
|
|
24
|
+
"assets": [],
|
|
25
|
+
"styles": [
|
|
26
|
+
"src/styles.css"
|
|
27
|
+
],
|
|
28
|
+
"scripts": []
|
|
29
|
+
},
|
|
30
|
+
"configurations": {
|
|
31
|
+
"production": {
|
|
32
|
+
"budgets": [
|
|
33
|
+
{
|
|
34
|
+
"type": "initial",
|
|
35
|
+
"maximumWarning": "500kb",
|
|
36
|
+
"maximumError": "1mb"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"type": "anyComponentStyle",
|
|
40
|
+
"maximumWarning": "2kb",
|
|
41
|
+
"maximumError": "4kb"
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
"outputHashing": "all"
|
|
45
|
+
},
|
|
46
|
+
"development": {
|
|
47
|
+
"optimization": false,
|
|
48
|
+
"extractLicenses": false,
|
|
49
|
+
"sourceMap": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"defaultConfiguration": "production"
|
|
53
|
+
},
|
|
54
|
+
"serve": {
|
|
55
|
+
"builder": "@angular-devkit/build-angular:dev-server",
|
|
56
|
+
"configurations": {
|
|
57
|
+
"production": {
|
|
58
|
+
"buildTarget": "encore-sdk-angular-example:build:production"
|
|
59
|
+
},
|
|
60
|
+
"development": {
|
|
61
|
+
"buildTarget": "encore-sdk-angular-example:build:development"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"defaultConfiguration": "development"
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
"cli": {
|
|
70
|
+
"analytics": false
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "encore-sdk-angular-example",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Angular example for Encore Web SDK",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"ng": "ng",
|
|
7
|
+
"start": "ng serve",
|
|
8
|
+
"build": "ng build",
|
|
9
|
+
"watch": "ng build --watch --configuration development"
|
|
10
|
+
},
|
|
11
|
+
"private": true,
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@angular/animations": "^17.3.0",
|
|
14
|
+
"@angular/common": "^17.3.0",
|
|
15
|
+
"@angular/compiler": "^17.3.0",
|
|
16
|
+
"@angular/core": "^17.3.0",
|
|
17
|
+
"@angular/forms": "^17.3.0",
|
|
18
|
+
"@angular/platform-browser": "^17.3.0",
|
|
19
|
+
"@angular/platform-browser-dynamic": "^17.3.0",
|
|
20
|
+
"@encorekit/web-sdk": "^0.1.1",
|
|
21
|
+
"rxjs": "~7.8.0",
|
|
22
|
+
"tslib": "^2.3.0",
|
|
23
|
+
"zone.js": "~0.14.3"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@angular-devkit/build-angular": "^17.3.0",
|
|
27
|
+
"@angular/cli": "^17.3.0",
|
|
28
|
+
"@angular/compiler-cli": "^17.3.0",
|
|
29
|
+
"typescript": "~5.4.2"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<div class="app">
|
|
2
|
+
<h1>🎯 Encore SDK</h1>
|
|
3
|
+
<p>Angular Example</p>
|
|
4
|
+
|
|
5
|
+
<div class="card">
|
|
6
|
+
<h2>SDK Status</h2>
|
|
7
|
+
<div class="user-info">
|
|
8
|
+
<strong>Status:</strong> {{ isInitialized ? '✓ Initialized' : '✗ Not Initialized' }}
|
|
9
|
+
<br />
|
|
10
|
+
<strong>User ID:</strong> {{ userId || 'Not set' }}
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
<div *ngIf="status" [class]="'status ' + status.type">
|
|
14
|
+
{{ status.message }}
|
|
15
|
+
</div>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
<div class="card">
|
|
19
|
+
<h2>User Identification</h2>
|
|
20
|
+
<div class="input-group">
|
|
21
|
+
<label for="userId">Custom User ID:</label>
|
|
22
|
+
<input
|
|
23
|
+
id="userId"
|
|
24
|
+
type="text"
|
|
25
|
+
placeholder="Enter user ID (e.g., user-123)"
|
|
26
|
+
[(ngModel)]="customUserId"
|
|
27
|
+
[disabled]="!isInitialized"
|
|
28
|
+
/>
|
|
29
|
+
</div>
|
|
30
|
+
<button
|
|
31
|
+
(click)="handleIdentifyUser()"
|
|
32
|
+
[disabled]="!isInitialized"
|
|
33
|
+
class="primary"
|
|
34
|
+
>
|
|
35
|
+
Identify User
|
|
36
|
+
</button>
|
|
37
|
+
</div>
|
|
38
|
+
|
|
39
|
+
<div class="card">
|
|
40
|
+
<h2>Present Offer</h2>
|
|
41
|
+
<p>Click the button below to display an offer to the user.</p>
|
|
42
|
+
<button
|
|
43
|
+
(click)="handlePresentOffer()"
|
|
44
|
+
[disabled]="!isInitialized"
|
|
45
|
+
class="success"
|
|
46
|
+
>
|
|
47
|
+
🎁 Present Offer
|
|
48
|
+
</button>
|
|
49
|
+
</div>
|
|
50
|
+
|
|
51
|
+
<div class="card">
|
|
52
|
+
<h2>Code Example</h2>
|
|
53
|
+
<pre>{{ codeExample }}</pre>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { Component, OnInit } from '@angular/core';
|
|
2
|
+
import { CommonModule } from '@angular/common';
|
|
3
|
+
import { FormsModule } from '@angular/forms';
|
|
4
|
+
import { EncoreService } from './encore.service';
|
|
5
|
+
|
|
6
|
+
interface Status {
|
|
7
|
+
message: string;
|
|
8
|
+
type: 'info' | 'success' | 'error';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
@Component({
|
|
12
|
+
selector: 'app-root',
|
|
13
|
+
standalone: true,
|
|
14
|
+
imports: [CommonModule, FormsModule],
|
|
15
|
+
templateUrl: './app.component.html',
|
|
16
|
+
})
|
|
17
|
+
export class AppComponent implements OnInit {
|
|
18
|
+
isInitialized = false;
|
|
19
|
+
userId = '';
|
|
20
|
+
customUserId = '';
|
|
21
|
+
status: Status | null = null;
|
|
22
|
+
|
|
23
|
+
codeExample = `// Initialize SDK
|
|
24
|
+
Encore.configure({
|
|
25
|
+
apiKey: 'your-api-key',
|
|
26
|
+
userId: 'user-123',
|
|
27
|
+
environment: 'production',
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
// Identify user with attributes
|
|
31
|
+
Encore.identify('user-123', {
|
|
32
|
+
email: 'user@example.com'
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// Present offer
|
|
36
|
+
const result = await Encore.presentOffer()
|
|
37
|
+
if (result.granted) {
|
|
38
|
+
console.log('Offer granted!')
|
|
39
|
+
}`;
|
|
40
|
+
|
|
41
|
+
constructor(private encoreService: EncoreService) {}
|
|
42
|
+
|
|
43
|
+
ngOnInit() {
|
|
44
|
+
try {
|
|
45
|
+
this.encoreService.initialize('ENCORE_PUBLIC_API_KEY', 'production');
|
|
46
|
+
this.userId = this.encoreService.getCurrentUserId() || '';
|
|
47
|
+
this.isInitialized = true;
|
|
48
|
+
this.status = {
|
|
49
|
+
message: 'Encore SDK initialized successfully!',
|
|
50
|
+
type: 'success',
|
|
51
|
+
};
|
|
52
|
+
} catch (error) {
|
|
53
|
+
this.status = {
|
|
54
|
+
message: `Failed to initialize SDK: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
55
|
+
type: 'error',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
handleIdentifyUser() {
|
|
61
|
+
if (!this.customUserId.trim()) {
|
|
62
|
+
this.status = {
|
|
63
|
+
message: 'Please enter a user ID',
|
|
64
|
+
type: 'error',
|
|
65
|
+
};
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
this.encoreService.identify(this.customUserId, {
|
|
71
|
+
email: 'user@example.com',
|
|
72
|
+
});
|
|
73
|
+
this.userId = this.customUserId;
|
|
74
|
+
this.status = {
|
|
75
|
+
message: `User identified as: ${this.customUserId}`,
|
|
76
|
+
type: 'success',
|
|
77
|
+
};
|
|
78
|
+
} catch (error) {
|
|
79
|
+
this.status = {
|
|
80
|
+
message: `Failed to identify user: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
81
|
+
type: 'error',
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async handlePresentOffer() {
|
|
87
|
+
this.status = {
|
|
88
|
+
message: 'Presenting offer...',
|
|
89
|
+
type: 'info',
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
try {
|
|
93
|
+
const result = await this.encoreService.presentOffer();
|
|
94
|
+
|
|
95
|
+
if (result.granted) {
|
|
96
|
+
this.status = {
|
|
97
|
+
message: 'Offer granted successfully!',
|
|
98
|
+
type: 'success',
|
|
99
|
+
};
|
|
100
|
+
} else {
|
|
101
|
+
this.status = {
|
|
102
|
+
message: `Offer not granted: ${JSON.stringify(result.reason)}`,
|
|
103
|
+
type: 'info',
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
} catch (error) {
|
|
107
|
+
this.status = {
|
|
108
|
+
message: `Failed to present offer: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
|
109
|
+
type: 'error',
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|