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 caseExample
SDK initialization controlInitialize Optimizely at runtime when App Studio auto-initialization is not used.
User identity mappingSet email or userId before push registration for accurate audience targeting.
Push token lifecycle updatesRe-register push after identifying a user to generate a token tied to that identity.
Permission managementPrompt users for notification permission and check grant status before registering.
Deep link routing from notificationsOpen 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:

  1. Enable the plugin config: Go to Plugin setup and complete Enable the plugin.
  2. Confirm runtime behavior: Review Configuration options for the active toggle behavior.
  3. Implement bridge calls: Add core methods from JavaScript bridge functions.
  4. Validate integration flow: Run the scenarios in Code examples.
  5. 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

SettingDescriptionDefaultRecommended
activeEnables or disables the Optimizely plugin integration.falsetrue 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:

ParameterTypeRequiredDescription
apiKeystringYesOptimizely API key used to initialize the SDK.
callbackfunctionNoOptional 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:

ParameterTypeRequiredDescription
callbackfunctionNoOptional 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:

ParameterTypeRequiredDescription
emailstringYesUser email address for identity mapping.
callbackfunctionNoOptional 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:

ParameterTypeRequiredDescription
userIdstringYesCustom user identifier for audience targeting.
callbackfunctionNoOptional 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:

ParameterTypeRequiredDescription
callbackfunctionNoOptional 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:

ParameterTypeRequiredDescription
callbackfunctionNoOptional 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:

ParameterTypeRequiredDescription
callbackfunctionNoOptional 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:

  • initialize returns { success: true }.
  • isInitialized reflects the expected state after initialization.
  • setEmail and setUserId each return { success: true }.
  • registerPush succeeds after user identity is set.
  • Plugin loads without JavaScript errors.
  • 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.
  • Invalid or missing API key is handled in the UI flow.
  • An initialization guard prevents duplicate initialize calls.
  • Permission-denied path is handled gracefully.
  • Network errors during push registration are caught and logged.
  • 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.
  • 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

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.

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.

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.

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.

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.