Embed the Preference Center
Create custom Preference Center UIs by fetching the config and building your own subscription management interface.
This guide covers creating custom Preference Center UIs for Cordova applications. Unlike the default Preference Center, you’ll build your own UI from scratch using the Preference Center configuration and subscription list APIs.
Override Default Display Behavior
To use a custom Preference Center instead of the default UI, disable auto-launch for the specific Preference Center ID and handle display events:
// Disable the OOTB UI for this Preference Center
Airship.preferenceCenter.setAutoLaunchDefaultPreferenceCenter(
"preference-center-id",
false
);
// Add a listener to handle display events
Airship.preferenceCenter.onDisplay((event) => {
const preferenceCenterId = event.preferenceCenterId;
// Navigate to your custom preference center UI
navigateToCustomPreferenceCenter(preferenceCenterId);
});Fetching Preference Center Config
The Preference Center config contains all the information needed to build your UI, including subscription lists, sections, and display settings.
Airship.preferenceCenter.getConfig("preference-center-id", (config) => {
// Use config to build your UI
});The config might not be available immediately on first app start. Implement exponential backoff if automatically retrying, or provide a UI for users to manually retry.
Building Your Custom UI
You’ll need to:
- Fetch the config to get the list of subscription lists and their current state
- Build your UI using the config data (sections, subscription lists, display settings)
- Update subscription lists when users make changes using the Subscription List APIs
Example Implementation
function loadPreferenceCenter(preferenceCenterId) {
Airship.preferenceCenter.getConfig(preferenceCenterId, (config) => {
// Build your UI with the config
const container = document.getElementById('preference-center');
// Display title
const title = document.createElement('h1');
title.textContent = config.display.name;
container.appendChild(title);
// Display sections
config.sections.forEach((section) => {
const sectionDiv = document.createElement('div');
const sectionTitle = document.createElement('h2');
sectionTitle.textContent = section.display.name;
sectionDiv.appendChild(sectionTitle);
// Display items (subscription lists)
section.items.forEach((item) => {
const itemDiv = document.createElement('div');
const label = document.createElement('label');
label.textContent = item.display.name;
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.checked = isSubscribed(item.subscriptionId);
checkbox.addEventListener('change', (e) => {
if (e.target.checked) {
Airship.contact.subscriptionLists.subscribe(item.subscriptionId);
} else {
Airship.contact.subscriptionLists.unsubscribe(item.subscriptionId);
}
});
itemDiv.appendChild(checkbox);
itemDiv.appendChild(label);
sectionDiv.appendChild(itemDiv);
});
container.appendChild(sectionDiv);
});
});
}Preference Center configuration is currently limited to subscription lists only. Use the Subscription List APIs to manage user subscriptions.
Categories