Send a capture with a custom trigger¶
Hook into an event, add data from that event to the capture and send the capture¶
In this example, we will hook into an event called 'myEvent'. We will add data from that event to the capture and then also immediately send the capture to the API.
You can use this example and update it to hook into other events from e.g. Mautic or Matomo, to send that event data to Unomi.
Example:
- sending Matomo goals to Unomi with our own trigger.
Snippet¶
window.dsdc = window.dsdc || function () { (dsdc.q = dsdc.q || []).push(arguments) }; dsdc.l = +new Date;
window.dsdcSettings = window.dsdcSettings || {};
dsdcSettings.preventCapture = dsdcSettings.preventCapture || {};
// turn the manual captures on (they are prevented by default)
dsdcSettings.preventCapture.manual = false;
window.dsdc('preventCapture', false, 'manual');
document.addEventListener('myEvent', function (e) {
var eventDataToCapture = function(data) {
console.log("before request");
var changedCapture = data.requestData;
changedCapture.te__myEvent_id = e.detail.id; // get data (id) from the event data
// update the capture with your new data
dsdc.updateCapture(changedCapture);
}
window.dsdc('beforeRequest', eventDataToCapture);
// send the capture
dsdc.sendCapture();
});