How you can use the Identity API to share reader-provided data with ad partners
Mediavine Identity API
The Mediavine Identity API is a public facing API that enables publishers to provide user-provided data to our partners. It is an asynchronous API that is available after the mediavineIdentityReady
occurs.
Event: mediavineIdentityReady
The mediavineIdentityReady
event occurs after the publicly available Mediavine Identity API methods are exposed on the window
object. Once this event occurs, the identityOptIn and identityOptOut methods are ready to be used. These Mediavine Identity API methods are explained in detail below.
Method 1:
window.$mediavine.web.identityOptIn(data, callback)
The window.$mediavine.web.identityOptIn
method accepts two arguments, an object data
and a function callback
which are explained in detail below.
Object: data
The data
object must contain the key email
with a value that is a string representing a valid email address or a valid email address in an SHA-1 or SHA-256 hex-encoded format:
plain text
{ email: 'johnsmith@website.com' }
SHA-1 hex-encoded equivalent of the above
{ email: '1b10110b0caf0a6569e00e97075cf60253b0bebc' }
SHA-256 hex-encoded equivalent of the above
{ email: 'f8d5da18dd78c78c4fc81dc136f31e885d5722297501f0bd17f92347c6393357' }
Function: callback
The callback
function receives just one parameter, an Error object, if there was an error using the Mediavine Identity API. Else, it will return null
when there is no error.
Example Usage
(() => {
window.addEventListener('mediavineIdentityReady', () => {
window.$mediavine.web.identityOptIn({
email: 'johnsmith@website.com'
}, (error) => {
if (error) {
// identity API failed, optionally check error message for details
// and determine how else to proceed return
console.error(error);
}
// success!
});
});
})();
Method 2:
window.$mediavine.web.identityOptOut(callback)
The window.$mediavine.web.identityOptOut(callback)
method accepts one argument, a callback
function.
Function: callback
The callback
function receives just one parameter, an Error object, if there was an error using the Mediavine Identity API. Else, it will return null
when there is no error.
Example Usage
(() => {
window.addEventListener('mediavineIdentityReady', () => {
window.$mediavine.web.identityOptOut((error) => {
if (error) {
// identity API failed, optionally check error message for details
// and determine how else to proceed return
console.error(error)
}
// success!
});
});
})();