Skip to main content
Javascript API Functions
Niels Baarsma avatar
Written by Niels Baarsma
Updated over a week ago

Loading the Rayn JS library provides a JavaScript object that responds to a few functions. These allow you to interact with the Rayn Javascript API and obtain data.

Get Content Categories

`getContentCategoriesIds(): Array<string>` 

This function returns an array of content category id's for the current page. This function may also return default taxonomy id's if they are present in the configuration. If there is no context data available for the given page and no defaults have been configured then the API will return an empty array. More information on how to work with content categories can be found here.

Example call:

const ContentCategoriesIds = await getContentCategoriesIds();

Example results:

["324", "54", "64"]
[]

Add (true) to only return the most relevant content category.

await raynJS.getContentCategoryIds(true)

Get Audience Cohort Categories

`getAudienceCategoriesIds(): Array<string>` 

This function returns an array of audience cohort id's (Cohorts) for the user. If there is no cohort data available for the given user then the API will return an empty array. More information on how to work with cohorts can be found here.

Example call:

const AudienceCategoriesIds = await getAudienceCategoriesIds();

Example results:

["274", "356"]
[]

Get Persona ID's

`getgetPersonaIds(): Array<string>` 

This function returns an array of persona id's (Personas) for the user. If there is no persona data available for the given user then the API will return an empty array. More information on personas can be found here.

Example call:

const getPersonaIds = await getPersonaIds();

Example results:

["274", "356"]
[]

Events

targetingSet

For event based loading RaynJS will emit an event once the setTargeting operation is completed. Example:

window.addEventListener("message", (message) => {
if (message.data.raynJSReturn) {
console.log("RaynJS message: ", message.data.raynJSReturn);
if ("targetingSet" in message.data.raynJSReturn) {
// message.data.raynJSReturn.targetingSet is boolean, true if raynJS has set targeting
console.log(`RaynJS set targeting: ${message.data.raynJSReturn.targetingSet}`);
}
}
});

How to retrieve data in the browser console

Test what context categories and audience categories Rayn has detected.

Go to a page where Rayn JS has been implemented

Open the browser console (right click anywhere on the page, click inspect and then select the Console tab)

Enter one of the following commands:

Get Persona ID's

await raynJS.getPersonaIds()

Get audience cohort categories

await raynJS.getAudienceCategoryIds()

Get content categories

(by default you will get categories from IAB Content Taxonomy 3.0)

await raynJS.getContentCategoryIds()

Add parameters to specify the wished output:

(“3.0”) = get categories from IAB Content Taxonomy 3.0

(“2.2”) = get categories from IAB Content Taxonomy 2.2

(true) = get only the highest scoring category from IAB Content Taxonomy 3.0

Example

await raynJS.getContentCategoryIds(“2.2”)
Example js functions.png
Did this answer your question?