Optimizely
Access Optimizely's push notification SDK from your Median app's JavaScript layer.
Business and Enterprise plugin
The Optimizely integration is available on Median's Business and Enterprise plans. These plans include expert app development, advanced native plugin access, dedicated technical support, and guaranteed App Store publishing, everything organizations need to launch and maintain mission-critical mobile apps.
Book a call with the Median team to discuss your requirements and get started.
The Optimizely plugin lets you initialize the SDK and manage push-related actions through the Median JavaScript Bridge. The plugin focuses on identifying users and controlling push registration and permission state from your web layer, giving you full control over the Optimizely SDK initialization without relying solely on App Studio auto-configuration.
Why use Optimizely
- Bridge-first integration: Call Optimizely actions directly from JavaScript without native code changes.
- Push workflow coverage: Request notification permission, check permission status, and register for push from a single API.
- User identity support: Set user email or user ID for audience targeting before registering push tokens.
- Flexible async pattern: Use callback style or promises.
Prerequisites
- A Median.co app with JavaScript Bridge enabled
- Optimizely API key
- Deep linking setup if you want notification links to open directly in-app
Optimizely is essential for apps that need to:
| Use case | Example |
|---|---|
| SDK initialization control | Initialize Optimizely at runtime when App Studio auto-initialization is not used. |
| User identity mapping | Set email or userId before push registration for accurate audience targeting. |
| Push token lifecycle updates | Re-register push after identifying a user to generate a token tied to that identity. |
| Permission management | Prompt users for notification permission and check grant status before registering. |
| Deep link routing from notifications | Open notification links directly inside the app after Deep Linking is configured. |
What you'll do
Use this section as a fast navigation map into the full setup and implementation details:
- Enable the plugin config: Go to Plugin setup and complete Enable the plugin.
- Confirm runtime behavior: Review Configuration options for the
activetoggle behavior. - Implement bridge calls: Add core methods from JavaScript bridge functions.
- Validate integration flow: Run the scenarios in Code examples.
- Verify edge cases: Complete Testing checklist and use Troubleshooting.
Plugin setup
Enable the plugin
To enable this plugin, book a call with the Median team to discuss your requirements and get started.
Configuration options
| Setting | Description | Default | Recommended |
|---|---|---|---|
active | Enables or disables the Optimizely plugin integration. | false | true in environments where Optimizely is required. |
Note: Notification links can open directly in the app when Deep Linking is configured.
JavaScript bridge functions
Initialize
Initialize Optimizely with an API key when not auto-configured in App Studio. For this function, provide a callback function or otherwise a promise is returned.
↔️Median JavaScript Bridge
// Using promises (recommended)
const result = await median.optimizely.initialize({ apiKey: 'YOUR_OPTIMIZELY_API_KEY' });
console.log('initialize result:', result);
// Using callback
median.optimizely.initialize({ apiKey: 'YOUR_OPTIMIZELY_API_KEY' }, function(result) {
console.log('initialize callback:', result);
}, function(err) {
console.error('Optimizely error (callback)', err);
});Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | string | Yes | Optimizely API key used to initialize the SDK. |
callback | function | No | Optional callback; otherwise a promise is returned. |
Return value:
interface OptimizelyInitializeResponse {
success: boolean;
}Check if Initialized
Check whether the Optimizely SDK is already initialized. For this function, provide a callback function, or a promise is returned.
↔️Median JavaScript Bridge
median.optimizely.isInitialized({'callback': function});Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
callback | function | No | Optional callback; otherwise a promise is returned. |
Return value:
interface OptimizelyIsInitializedResponse {
initialized: boolean;
apiKey?: string;
}Set Email
Identify the user by email address in Optimizely. Call registerPush after this to generate a new push token associated with the identified user. For this function, provide a callback function or otherwise a promise is returned.
↔️Median JavaScript Bridge
median.optimizely.setEmail({'email': '[email protected]', 'callback': function});Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
email | string | Yes | User email address for identity mapping. |
callback | function | No | Optional callback; otherwise a promise is returned. |
Return value:
interface OptimizelySetIdentityResponse {
success: boolean;
}Set User Id
Identify the user by a custom ID in Optimizely. Call registerPush after this to generate a new push token associated with the identified user. For this function, provide a callback function or a promise is returned.
↔️Median JavaScript Bridge
median.optimizely.setUserId({'userId': 'user-123', 'callback': function});Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
userId | string | Yes | Custom user identifier for audience targeting. |
callback | function | No | Optional callback; otherwise a promise is returned. |
Return value:
interface OptimizelySetIdentityResponse {
success: boolean;
}Register For Push Notifications
Register the current user for push and generate a new push token. Call this after setting the user identity to ensure the token is associated with the identified user. For this function, provide a callback function, or a promise is returned.
↔️Median JavaScript Bridge
median.optimizely.registerPush({'callback': function});Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
callback | function | No | Optional callback; otherwise a promise is returned. |
Return value:
interface OptimizelyRegisterPushResponse {
success: boolean;
}Prompt for Push Notification Permission
Prompt the user to grant notification permission. For this function, provide a callback function, or otherwise a promise is returned.
↔️Median JavaScript Bridge
median.optimizely.requestPermission({'callback': function});Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
callback | function | No | Optional callback; otherwise a promise is returned. |
Return value:
interface OptimizelyPermissionResponse {
granted: boolean;
}Check Push Notification Permission Status
Check the current notification permission state without prompting the user. For this function, provide a callback function, or a promise is returned.
↔️Median JavaScript Bridge
median.optimizely.permissionStatus({'callback': function});Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
callback | function | No | Optional callback; otherwise a promise is returned. |
Return value:
interface OptimizelyPermissionResponse {
granted: boolean;
}Testing checklist
Use this checklist to ensure Optimizely is working correctly in your app:
Basic Functionality
-
initializereturns{ success: true }. -
isInitializedreflects the expected state after initialization. -
setEmailandsetUserIdeach return{ success: true }. -
registerPushsucceeds after user identity is set. - Plugin loads without JavaScript errors.
Platform Testing
- Permission request flow works on iOS.
- Android 13+ shows the system permission dialog.
- Android 12 and below grants permission without a dialog prompt.
- Plugin gracefully handles platform differences.
Error Scenarios
- Invalid or missing API key is handled in the UI flow.
- An initialization guard prevents duplicate
initializecalls. - Permission-denied path is handled gracefully.
- Network errors during push registration are caught and logged.
Edge Cases
- Push registration is re-run after identity updates.
- Deep link notification opens the correct route in-app when configured.
- Both promise and callback invocation styles work in your integration.
User Experience
- Users receive a clear prompt when notification permission is requested.
- App provides a fallback experience when push permission is denied.
- No duplicate permission prompts appear after the user has already responded.
- Plugin does not interfere with app navigation or page transitions.
Troubleshooting
Optimizely functions are undefined or not working
Confirm the JavaScript Bridge is enabled in Median App Studio and that the plugin is active. Also verify you are calling bridge functions after the page and bridge have fully loaded.
`isInitialized` remains false after calling `initialize`?
Ensure you passed a valid apiKey to initialize and that the call returned { success: true }. If initialization failed silently, check for network issues or an incorrect API key, then retry.
Push notifications are not arriving after login?
After setting user identity with setEmail or setUserId, you must call registerPush to generate a new token associated with that user. Skipping this step means the push token is not linked to the newly identified user.
Notification links do not open inside the app?
Deep Linking must be configured in your app for notification links to open directly in-app. Without Deep Linking, tapping a notification will open the device's default browser instead.
Permission dialog does not appear on Android?
On Android 12 and below, push permission is granted automatically without a dialog. On Android 13+, the system permission dialog is required. Verify you are calling requestPermission and testing on a device or emulator running Android 13 or higher to see the dialog.
Still having trouble?For issues related to Optimizely's own configuration, permissions, or platform-specific behavior outside Median.co, refer to Optimizely's integration documentation.
Updated 10 days ago