News
Richie JavaScript API
JavaScript API
All article pages must import a file called mraid.js
(using <script src="…">
tag) as the first JS file in each article HTML file. This file will be made available at runtime by the native apps. It must not be included as part of the article HTML files themselves.
getUserToken()
richie.getUserToken()
- If user is logged in, the JWT token of current user.
undefined
otherwise
getAnalyticsData()
This function returns a value from analytics_data
object associated with one of the following contexts:
- section
- article
- user entitlements
Let's assume that user is viewing an article with the following analytics_data
:
Let's also assume that this article belongs to a section with the following analytics_data
:
Let's also assume that current user is logged in, and the response object of Richie Entitlements API received the following analytics_data
after last token refresh:
In this context, getAnalyticsData()
API would return the following values
getAnalyticsData("article.author") == "James Smith"
getAnalyticsData("section.scope") == "regional"
getAnalyticsData("entitlements.nickname") == "Jamie"
getAnalyticsData("entitlements.membership.start_year") == 2018
getAnalyticsData("entitlements.membership.level") == "premium"
getAnalyticsData() == {
"article": {
"author": "James Smith"
},
"entitlements": {
"nickname": "Jamie",
"membership": {
"start_year": 2018
"level": "premium"
}
},
"section": {
"scope": "regional"
}
}
getCCPAOptOut()
richie.getCCPAOptOut()
Richie apps can be configured to support California Consumer Privacy Act (CCPA). When CCPA support is enabled, user will be able to view a CCPA page where user can opt-out of collection of personal information (the "Do Not Sell My Personal Information" page).
This function will return the following values:
true
: user has opted outfalse
: user has opted innull
: user hasn't yet viewed the CCPA page, or hasn't yet made an explicit decision, or CCPA support is not enabled for the current app
Global persisted parameters
News articles are loaded into WebViews which have limited access to such standard persistence mechanisms as cookie storage or JS LocalStorage APIs. Instead, Richie apps provide its own solution for persisting values across WebView instances and app usage sessions.
Set persisted global parameter which can be retrieved later. Setting parameter to null
unsets it.
Get persisted global parameter. Returns null
in callback if key was not set.
triggerAnalyticsEvent()
richie.triggerAnalyticsEvent(analyticsEventName, analyticsEventParams)
Triggers analytics event with name analyticsEventName
by passing parameters to it defined in the analyticsEventParams
object. Supported analytics events are defined by Richie in a separate Richie Analytics specification (contact Richie directly to get a copy).
Sample: