Using Engine API to trigger metrics

Engine API is an alternative approach to using EventTrack to triggering metrics

Using Engine API to trigger metrics in a client side manner does not require Engine API to be enabled on your site - it is supported "out of the box" for this use case.

The following is an example:

var engineapimetricpostdata = {
"visits": [{
"Data": {
"113325": {
"Hits": 1
},
"113329": {
"Hits": 1
}
}
}],
"cookies": {
"SSOD": "AP52AAAAIACtugEABAAAAEGmmmBT4ZtgsboBAAQAAABBpppgU-GbYAAA",
"SSRT": "U-GbYAADAA",
"SSSC": "808.G6961058701578968086.1|4876.132187",
"SSID": "CACv3B0OAAAAAAACpppgFpxBAAKmmmABAAAAAAAAAAAAAqaaYAAV3QwTAANbBAIAAqaaYAEA"
}
}

var xhr = new XMLHttpRequest();
xhr.open("POST", "https://yourdomain.com/__ssobj/api", true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
xhr.setRequestHeader('Sec-Datadog', 'test123');
xhr.send(JSON.stringify(engineapimetricpostdata));
xhr.onloadend = function() {
if (xhr.status != 200) {
console.log(`Error ${xhr.status}: ${xhr.statusText}`);
} else {
console.log(`Done, got ${xhr.response.length} bytes`);
}
};

Note: Cookies do not need to be sent in the payload if they are already being sent in the browser. Cookie values sent in the payload will take precedence if there are also cookie being sent.

more information on Engine API