|
| 1 | +# @prosdevlab/experience-sdk |
| 2 | + |
| 3 | +A lightweight, explainable client-side experience runtime built on [@lytics/sdk-kit](https://github.com/lytics/sdk-kit). |
| 4 | + |
| 5 | +**Size:** 6.9 KB gzipped (includes core + 3 plugins) |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- **Explainability-First** - Every decision includes structured reasons |
| 10 | +- **Plugin-Based** - Built on sdk-kit's powerful plugin system |
| 11 | +- **Multiple Buttons** - Primary, secondary, and link variants |
| 12 | +- **Frequency Capping** - Control impression limits per session/day/week |
| 13 | +- **Responsive Layout** - Automatically adapts to mobile/desktop |
| 14 | +- **Script Tag Ready** - Works without build tools |
| 15 | +- **Type-Safe** - Full TypeScript support |
| 16 | + |
| 17 | +## Installation |
| 18 | + |
| 19 | +### npm |
| 20 | + |
| 21 | +```bash |
| 22 | +npm install @prosdevlab/experience-sdk |
| 23 | +``` |
| 24 | + |
| 25 | +### Script Tag |
| 26 | + |
| 27 | +```html |
| 28 | +<script src="https://unpkg.com/@prosdevlab/experience-sdk/dist/experience-sdk.global.js"></script> |
| 29 | +``` |
| 30 | + |
| 31 | +## Quick Start |
| 32 | + |
| 33 | +### For Bundlers (ESM) |
| 34 | + |
| 35 | +```typescript |
| 36 | +import { createInstance } from '@prosdevlab/experience-sdk'; |
| 37 | + |
| 38 | +// Create instance |
| 39 | +const experiences = createInstance({ debug: true }); |
| 40 | + |
| 41 | +// Initialize |
| 42 | +await experiences.init(); |
| 43 | + |
| 44 | +// Register a banner |
| 45 | +experiences.register('welcome', { |
| 46 | + type: 'banner', |
| 47 | + targeting: { |
| 48 | + url: { contains: '/' } |
| 49 | + }, |
| 50 | + content: { |
| 51 | + title: 'Welcome!', |
| 52 | + message: 'Thanks for visiting.', |
| 53 | + buttons: [ |
| 54 | + { text: 'Get Started', url: '/start', variant: 'primary' } |
| 55 | + ] |
| 56 | + }, |
| 57 | + frequency: { |
| 58 | + max: 3, |
| 59 | + per: 'session' |
| 60 | + } |
| 61 | +}); |
| 62 | + |
| 63 | +// Evaluate and show |
| 64 | +const decision = experiences.evaluate(); |
| 65 | +console.log(decision.reasons); |
| 66 | +``` |
| 67 | + |
| 68 | +### For Script Tag |
| 69 | + |
| 70 | +```html |
| 71 | +<script src="https://unpkg.com/@prosdevlab/experience-sdk/dist/experience-sdk.global.js"></script> |
| 72 | +<script> |
| 73 | + // Global 'experiences' available |
| 74 | + experiences.init({ debug: true }); |
| 75 | + |
| 76 | + experiences.register('cookie-consent', { |
| 77 | + type: 'banner', |
| 78 | + content: { |
| 79 | + message: 'We use cookies to improve your experience', |
| 80 | + buttons: [ |
| 81 | + { text: 'Accept', action: 'accept', variant: 'primary' }, |
| 82 | + { text: 'Reject', action: 'reject', variant: 'secondary' } |
| 83 | + ], |
| 84 | + position: 'bottom' |
| 85 | + } |
| 86 | + }); |
| 87 | + |
| 88 | + experiences.evaluate(); |
| 89 | +</script> |
| 90 | +``` |
| 91 | + |
| 92 | +## Multiple Buttons |
| 93 | + |
| 94 | +Banners support multiple buttons with visual variants: |
| 95 | + |
| 96 | +```typescript |
| 97 | +buttons: [ |
| 98 | + { text: 'Accept all', variant: 'primary', action: 'accept' }, |
| 99 | + { text: 'Reject', variant: 'secondary', action: 'reject' }, |
| 100 | + { text: 'Preferences', variant: 'link', url: '/preferences' } |
| 101 | +] |
| 102 | +``` |
| 103 | + |
| 104 | +- **primary** - Blue button for main actions |
| 105 | +- **secondary** - Gray outlined button for secondary actions |
| 106 | +- **link** - Text link style for tertiary actions |
| 107 | + |
| 108 | +## Events |
| 109 | + |
| 110 | +Listen to experience interactions: |
| 111 | + |
| 112 | +```typescript |
| 113 | +// Banner shown |
| 114 | +experiences.on('experiences:shown', ({ experienceId }) => { |
| 115 | + console.log('Shown:', experienceId); |
| 116 | +}); |
| 117 | + |
| 118 | +// Button clicked |
| 119 | +experiences.on('experiences:action', ({ experienceId, action, variant, metadata }) => { |
| 120 | + analytics.track('Experience Action', { experienceId, action }); |
| 121 | +}); |
| 122 | + |
| 123 | +// Banner dismissed |
| 124 | +experiences.on('experiences:dismissed', ({ experienceId }) => { |
| 125 | + console.log('Dismissed:', experienceId); |
| 126 | +}); |
| 127 | +``` |
| 128 | + |
| 129 | +## Included Plugins |
| 130 | + |
| 131 | +This package includes three official plugins: |
| 132 | + |
| 133 | +- **Banner Plugin** - DOM rendering with responsive layout |
| 134 | +- **Frequency Plugin** - Impression tracking and capping |
| 135 | +- **Debug Plugin** - Logging and window events |
| 136 | + |
| 137 | +## Documentation |
| 138 | + |
| 139 | +- [Full Documentation](https://prosdevlab.github.io/experience-sdk) |
| 140 | +- [API Reference](https://prosdevlab.github.io/experience-sdk/reference) |
| 141 | +- [Plugins Guide](https://prosdevlab.github.io/experience-sdk/reference/plugins) |
| 142 | +- [Examples](https://prosdevlab.github.io/experience-sdk/demo) |
| 143 | + |
| 144 | +## License |
| 145 | + |
| 146 | +MIT |
| 147 | + |
0 commit comments