Skip to main content
Identity API

How you can use the Identity API to share reader-provided data with ad partners

Jacob Feltner avatar
Written by Jacob Feltner
Updated over 3 years ago

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 SHA-1 hex-encoded format:

{ email: 'johnsmith@website.com' }

or the SHA-1 hex-encoded equivalent of the above

{ email: '1b10110b0caf0a6569e00e97075cf60253b0bebc' }

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!
});
});
})();
Did this answer your question?