JavaScript SDK
The SDK is the script that manages widgets on your page. It's in charge of getting content (whether editorial or sponsored) and place it correctly in your pages.
- It initialises and identifies the page as yours
- It calls our content server to check if there's content to display
- It watches the page for changes, so that if a new slot is available, it can be filled
Installation#
Add this code right after the opening <body> tag, and replace
YOUR_ACCOUNT_ID with your actual account id.
the
beOpAsyncInitis where you identify your page using theinit()function, and thewatch()tells the SDK to look for slots, the script below is the actual SDK, which is loaded asynchronously (meaning it doesn't block your page)
Installing on Wordpress#
It's possible that your Wordpress setup concatenates scripts, which prevents you from running an up-to-date Collective Audience SDK and creates unexpected bugs.
For that, you can use the following SDK:
Declaring slots#
You can declare slots, or places where widgets should appear by simply putting the following tag where you want them on your pages:
In order to ensure your slots are correctly filled, we highly recommend naming them, this way if the slot order in your page is altered, the SDK will still be able to identify them.
Example:
You can specify if a slot is strictly for your own editorial content or for sponsored content too:
Browser support#
We support all modern browsers.
Following Microsoft's own products, we've discontinued Internet Explorer support.
Need to check if you installed the SDK correctly?#
Come and check the Diagnostics script!
API Reference#
BeOpSDK.init(config)#
Initialises the SDK with your account.
config.account: your Collective Audience account IDconfig.canAccessStorage(default:true): set to false to prevent Collective Audience from storing a technical cookie in the absence of a TCF consent platformconfig.refreshExistingSlots(default:true): set to false if your website loads new articles with an infinite scroll mechanismconfig.prefillInformations: provide user information to ease the form/optin filling process (useful if your user is logged in on your account).You can provide the elements like follows (all keys are optional):
BeOpSDK.init({account: "abcdef1234567890abcdef12",prefillInformations: {firstName: "Foo",lastName: "Bar",phoneNumber: "+336...",},});
BeOpSDK.watch()#
Parses and watches the page for available slots.
BeOpSDK.parse()#
Parses the page for tags
caution
Deprecated: use BeOpSDK.watch(), which is reliable even when pages aren't fully loaded or blocked by a longer loading
BeOpSDK.pushEvent(event)#
Send an event to Collective Audience's server.
event.eventName: the name of the event. For now, onlyimpressionis supportedevent.eventValue: the value of the event. You can pass any string hereevent.slotName: the name of the slot where the event comes fromevent.currency(default: Computed from the account owning the slot): the currency of the event. OnlyEURandUSDare supported for now
Fullsize mode#
You might want to have a Collective Audience slot to take the whole viewport (for instance in a mobile iframe). To that end, you can add a data-expand attribute to make a slot fill the window.
If you want to be able to have a close button to appear once the creative is complete, add the following right after the BeOpSDK.init call:
Optionnally, you can pass a timeout param to trigger the button appearance in case of inactivity (defaults to 10s):
caution
The close button will not appear unless you provide your onPressClose event listener.
SDK API inventory#
This section lists all init parameters and public functions available in the current SDK. Parameters or functions not described in detail above may be documented in other pages or reserved for specific use cases.
BeOpSDK.init(config) โ parameters#
| Parameter | Type | Documented above | More details |
|---|---|---|---|
account | string | โ | Your publisher account ID (use with publisher path). |
network | string | โ | Your network account ID (use with network path). See Network SDK. |
networkPartnerID | string | โ | Optional site/placement identifier for reporting. See Network SDK. |
networkPublisherID | string | โ | Optional per-slot publisher override (network path). See Network SDK. |
canAccessStorage | boolean | โ | Default true. Cookie storage in absence of TCF. |
refreshExistingSlots | boolean | โ | Default true. Set false for infinite scroll. |
prefillInformations | object | โ | firstName, lastName, email, phoneNumber. |
pageUrl | string | โ | Override page URL used for content requests (e.g. canonical URL). |
onContentReceive | function | โ | Callback when content is received. |
onHeightChange | function | โ | Callback when widget height changes (e.g. iframe resize). |
siteUserID | string | โ | Optional site-specific user identifier. |
waitForTCF | boolean | โ | Wait for TCF consent before init. See Consent management. |
waitForEIDS | boolean | โ | Wait for EIDs before init (default true). |
gdpr | string | โ | Programmatic GDPR flag (e.g. "0" / "1"). |
gdprConsent | string | โ | TC string when no CMP is present. |
bpsegs | array of string | โ | Publisher first-party segments. See Network SDK (Prebid). |
clickUrlPrefix | string | โ | Optional prefix for click URLs. |
prebidVersion | string | โ | Prebid version when using header bidding. |
Public functions#
| Function | Documented above | More details |
|---|---|---|
BeOpSDK.init(config) | โ | See API Reference above. |
BeOpSDK.watch(rootElement?) | โ | Parses and watches for slots; triggers content fetch. |
BeOpSDK.parse(rootElement?) | โ (deprecated) | Use watch() instead. |
BeOpSDK.pushEvent(config) | โ | eventName, eventValue, eventLabel, slotName, currency. Only impression is supported for eventName. |
BeOpSDK.onPressClose(callback, timeout?) | โ | Fullsize mode: close button after creative complete. |
BeOpSDK.subscribeToWidgetEvents(callback) | โ | Subscribe to widget-level events (e.g. vote, interaction). |
BeOpSDK.getLoginStatus(callback) | โ | Get current login status and user ID (e.g. CrossConnect). |
Page keywords (not in init)#
Keywords are not passed in init(). Set window.beOpKeywords (array of strings) before the SDK runs; the SDK reads it at request time and sends it as kwds to the content server. See Identify pages โ Page keywords and Retail Media Network โ Passing context.