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.
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.
Init the script with your token. This call is mandatory and must be used before any mics.push() or mics.pushDefault().
name | type | description |
token | string | Your site token given by Mediarithmics. |
Returns : nothing.Throws : an error if the token is invalid.
mics.init("MY_TOKEN");
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.init({
mode: "VISIT",
site_token: "SITE TOKEN",
domain_name: "analytics.mydomain.com"
});
Push the default event $page_view to mediarithmics..
Arguments : none.
Returns : nothing.
Throws : an error if mics.init has not been called.
mics.init("SITE TOKEN");
mics.pushDefault();
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.init("<SITE_TOKEN>");
mics.push("my_event", {
my_prop1 : "value1",
my_prop2 : 42
});
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.addProperty("$user_account_id", <your unique user account id> );
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
mics.addProperties({
prop1 : "val1",
prop2 : "val2"
});
It can be used to declare global properties to push :
mics.addProperties({
prop1 : "val1",
prop2 : "val2"
});
// will push prop1, prop2 and prop3
mics.push("my_event", {
prop3 : "val3"
});
// will push prop1, prop2 and prop4
mics.push("my_event", {
prop4 : "val4"
});
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)
mics.addIdentifier(
"USER_ACCOUNT",
{ $user_account_id: "account id", $compartment_token: "token" }
);
mics.addIdentifier(
"USER_MAIL",
{ $email_hash: "hash", $email: "email" }
);
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.init("<SITE_TOKEN>");
mics.push("my_event", {
my_prop1 : "value1",
my_prop2 : 42
});
var start = new Date().getTime();
mics.onFinish(function(success) {
var end = new Date().getTime();
// end - start will be > 1000, but close to.
console.log("done with success : ", success, " in ", end - start, "ms");
},1000);
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.init("<SITE_TOKEN>");
mics.push("my_event", {
my_prop1 : "value1",
my_prop2 : 42
});
var start = new Date().getTime();
mics.onStart(function() {
var end = new Date().getTime();
console.log("started in ", end - start, "ms");
});
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("init", "<SITE_TOKEN>");
mics.call("push", "<EVENT_NAME>", {
my_prop1 : "value1",
my_prop2 : 42
});
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 1yr ago