Advanced Usage
Consent Change Events
Section titled “Consent Change Events”React to consent updates
Section titled “React to consent updates”Use onConsentChange() to receive a normalized snapshot after each consent submission.
Even when snapshot.status is COLLECTED, individual plugin block decisions must be evaluated separately — consent may have been granted at the category level but a specific plugin within that category could still be blocked. Use snapshot.categories (the same structure as getConsentedCategories()) alongside api.resolvePluginBlockedStatus() to determine the correct action for each plugin.
var unsubscribe = api.onConsentChange(function (snapshot) { if (snapshot.status === api.ConsentStatus.COLLECTED) { // Overall consent collected — evaluate each plugin's block status // from the snapshot's category structure before enabling features. var analyticsBlocked = api.resolvePluginBlockedStatus("Google Analytics");
if (analyticsBlocked === false) { enableAnalytics(); } else { disableAnalytics(); } }
renderConsentState(snapshot);});
// Remove listener on teardownunsubscribe();Snapshot fields:
status: consent lifecycle value (api.ConsentStatus.*)categories: category and plugin snapshot — same structure asgetConsentedCategories(), ornulllocalClientId: device-scoped client ID ornullisExpired: expiry flagexpiry:Dateornull
SDK events
Section titled “SDK events”| Event | Fired on | Detail | When |
|---|---|---|---|
sp:sdk-ready | window | { sp, api } | Core SDK initialized and SPTizenAPI ready |
sp:tv-mode-enabled | window | { tv: true, forced: boolean } | TV environment detected before Core SDK load. forced is true when detection was bypassed via SPTizenConfig.forceTVMode |
window.addEventListener("sp:sdk-ready", function (event) { var api = event.detail.api; mountConsentUi(api);});Handling Unique Client ID
Section titled “Handling Unique Client ID”Secure Privacy Tizen SDK generates a unique client ID for the device. Retrieve it using:
const clientId = api.getClientId();This clientId can be used to associate the user’s consent with internal identifiers in your app or backend systems.
Get Country Code
Section titled “Get Country Code”Returns the two-letter ISO 3166-1 alpha-2 country code detected by the SDK for this device, or null if it has not been resolved yet.
const countryCode = api.getCountryCode();// → 'IN' | 'US' | 'DE' | nullThe country code reflects the geographic location resolved at the time consent was first collected. The CMP uses it to determine which regional privacy regulation applies (for example, GDPR for EU countries).