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.
1
mics.init("MY_TOKEN");
Copied!

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.
1
mics.init({
2
mode: "VISIT",
3
site_token: "SITE TOKEN",
4
domain_name: "analytics.mydomain.com"
5
});
Copied!

mics.pushDefault()

Push the default event $page_view to mediarithmics..
Arguments : none. Returns : nothing. Throws : an error if mics.init has not been called.
1
mics.init("SITE TOKEN");
2
mics.pushDefault();
Copied!

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.
1
mics.init("<SITE_TOKEN>");
2
mics.push("my_event", {
3
my_prop1 : "value1",
4
my_prop2 : 42
5
});
Copied!

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.
1
mics.addProperty("$user_account_id", <your unique user account id> );
Copied!

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
1
mics.addProperties({
2
prop1 : "val1",
3
prop2 : "val2"
4
});
Copied!
It can be used to declare global properties to push :
1
mics.addProperties({
2
prop1 : "val1",
3
prop2 : "val2"
4
});
5
6
// will push prop1, prop2 and prop3
7
mics.push("my_event", {
8
prop3 : "val3"
9
});
10
11
// will push prop1, prop2 and prop4
12
mics.push("my_event", {
13
prop4 : "val4"
14
});
Copied!

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
name
type
description
type
string
The type of identifier. Accepted values: "USER_ACCOUNT", "USER_EMAIL"
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" } and if type is "USER_EMAIL", identifier must be { $email_hash: "hash" } or { $email_hash: "hash", $email: "email" }
Returns : nothing (if arguments are invalid, call to this method will have no effect)
1
mics.addIdentifier(
2
"USER_ACCOUNT",
3
{ $user_account_id: "account id", $compartment_token: "token" }
4
);
5
mics.addIdentifier(
6
"USER_MAIL",
7
{ $email_hash: "hash", $email: "email" }
8
);
Copied!

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.
1
mics.init("<SITE_TOKEN>");
2
mics.push("my_event", {
3
my_prop1 : "value1",
4
my_prop2 : 42
5
});
6
var start = new Date().getTime();
7
mics.onFinish(function(success) {
8
var end = new Date().getTime();
9
// end - start will be > 1000, but close to.
10
console.log("done with success : ", success, " in ", end - start, "ms");
11
},1000);
Copied!

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
1
mics.init("<SITE_TOKEN>");
2
mics.push("my_event", {
3
my_prop1 : "value1",
4
my_prop2 : 42
5
});
6
var start = new Date().getTime();
7
mics.onStart(function() {
8
var end = new Date().getTime();
9
console.log("started in ", end - start, "ms");
10
});
Copied!

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
1
mics.call("init", "<SITE_TOKEN>");
2
mics.call("push", "<EVENT_NAME>", {
3
my_prop1 : "value1",
4
my_prop2 : 42
5
});
Copied!

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
Last modified 3mo ago