JS Tag
This library allows mediarithmics customers to track user events on web sites and applications.
It loads a Javascript object in the page that can be used to send the proper events to the mediarithmics platform.
Please refer to the Web apps real time user tracking guide for details on how to use it.
When added to the page, the tag does 3 things :
Adding the mediarithmics cookie
If set up, start cookie-matching with partners
Register events
Cookies used by the tag are considered ad-serving cookies. You must get the user consent before using it.
mics.init(token)
Init the script with your token. This call is mandatory and must be used before any mics.push() or mics.pushDefault().
Arguments
name
type
description
token
string
Your site token given by Mediarithmics.
Returns : nothing.Throws : an error if the token is invalid.
mics.init({mode, site_token, domain_name})
Advanced way of initializing the TAG. Init the script with the mode of interaction, your site token and optionaly the custom domain name.
This call is mandatory and must be used before any mics.push() or mics.pushDefault().
Arguments
name
type
description
mode
string
The mode of interaction (in most cases it's a "VISIT"). In case of any doubt, please contact your mediarithmics account manager.
site_token
string
Your site token given by mediarithmics.
domain_name
object
(optional) The custom domain_name used to store the cookie on your domain, you should only use it when you use a custom DMP domain Ex: analytics.mydomain.com
Returns : nothing.Throws : an error if the token is invalid.
mics.pushDefault()
Push the default event $page_view to mediarithmics..
Arguments : none. Returns : nothing. Throws : an error if mics.init has not been called.
mics.push(event, properties)
Push a custom event with custom properties.
Arguments
name
type
description
event
string
the name of the event.
properties
object
the object containing the custom properties to push. Only string/boolean/number values are supported.
Returns : nothing. Throws : an error if mics.init has not been called.
mics.addProperty(name, value)
Add a single property to be used for each mics push or pushDefault. You can call this method multiple times, the effects are cumulative.
See mics.addProperties(properties) to send multiple properties at once.
Arguments
name
type
description
name
string
the name of the property to add.
value
object
the value of the property to add.
Returns : nothing. Throws : nothing.
mics.addProperties(properties)
Add properties to be used for each mics.push or mics.pushDefault. You can call this method multiple times, the effects are cumulative.
See mics.addProperty(name, value) to send only one property at once.
Arguments
name
type
description
properties
object
the object containing the custom properties to push. Only string/boolean/number values are supported.
Returns : nothing Throws : nothing
It can be used to declare global properties to push :
mics.addIdentifier(type,identifier)
Add an identifier to be used for each mics.push or mics.pushDefault. You can call this method multiple times with different identifier to add multiple identifiers. The effect of this method is idempotent: you can call it multiple times with the same input, the identifier will be registered only once.
Arguments
type
string
The type of identifier. Accepted values: "USER_ACCOUNT", "USER_EMAIL", and "USER_AGENT"
identifier
object
The object containing the identifier. Accepted values : - if type is "USER_ACCOUNT", identifier must be { $user_account_id: "account id"} or { $user_account_id: "account id", $compartment_token: "token" } - if type is "USER_EMAIL", identifier must be { $email_hash: "hash" } or { $email_hash: "hash", $email: "email" } - if type is "USER_AGENT", identifier must be { $user_agent_id: "user_agent_id" }. See UserAgentId. Agent type accepted are mobile advertising id, mobile vendor id, tv advertising id, and custom id.
You should not add network device id here as they are managed from the UI. If the desired network device id is not available please contact support.
Returns : nothing (if arguments are invalid, call to this method will have no effect)
mics.onFinish(callback, timeout)
Register ONE callback to fire when the tag has finished sending events. Only the last registered callback will be fired.
Arguments
name
type
description
callback
function
function taking a boolean. True if everything was OK.
timeout
int
The timeout in milliseconds to start triggering events. Will call callback after event replies.
Returns : nothing.
mics.onStart(callback)
Register ONE callback to be fired when the tag starts executing (ie the JavaScript is loaded and starts working). Only the last registered callback will be fired.
Arguments
name
type
description
callback
function
function called when tag start executing
Returns : nothing
mics.call(methodName, args)
Helper function to call a method without a snippet declaring it. Acts like a proxy function.
Arguments
name
type
description
methodName
string
the name of the method : (init, push, pushDefault, ...)
arguments
object...
the parameters of the method
Returns : underlying method result
mics.call("syncFeeds")
The syncFeeds method should be called after mics.init() to enable client-side feeds. It allows the tag to query mediarithmics servers to know if the user is in a segment synchronized with a client-side feed.
Arguments
name
type
description
methodName
string
syncFeeds
arguments
object...
none
Returns : Client-side feeds are now enabled
Session storage
For caching and integration purposes, the tag stores identifiers it retrieves in the browser session storage under the key mcssids
.
The value is a stringified object with keys corresponding to the site token and the value an array of identifiers like the following :
The session storage is specific to each browser tab and is erased when the tab is closed, making this storage temporary.
Last updated