Usage
Token detection
The SDK uses the microphone to capture the surrounding sound and search for SonicMedia tokens, and requires the microphone permission.
The token detection can be started and stopped at any time.
import SonicMedia from "@sonicmedia/sdk";
await SonicMedia.start();
// ...
SonicMedia.stop();
When calling the start method, the browser will prompt the user to grant the microphone permission if it hasn't been granted yet.
Synchronization
The SDK synchronizes the campaign scheduling metadata. It is run automatically when the SDK is initialized and can be manually requested from the application by calling the synchronize method.
The synchronization process occurs in the background and uses differential updates to minimize data usage. It also downloads and caches the images for the campaigns that could be potentially triggered.
await SonicMedia.synchronize();
It's not required to pause the detection process to do a synchronization.
Event handling
When a token is detected, the SDK checks for the campaigns that meet the conditions defined in the CMS (schedule, categories, repetition time, etc.), and if a matching campaign is found, then an event with all the relevant data is raised in order for the web app to take appropriate actions, like displaying the campaign image.
SonicMedia.onTrigger = (trigger) => {
// trigger contains the campaign metadata that can be used for the campaign display
console.log(trigger);
};