Using the Javascript Methods¶
In these examples we showcase what you can do with the javascript API.
Read capture BEFORE capture is saved and sent to Unomi¶
In this example we print the data which will be sent to Unomi:
<script>
window.dsdc = window.dsdc || function () { (dsdc.q = dsdc.q || []).push(arguments) }; dsdc.l = +new Date;
window.dsdc('beforeRequest', function (data) {
// read the capture data before script is loaded
console.log(data.requestData);
});
</script>
Read & modify capture BEFORE it was saved and sent to Unomi¶
Remove data from capture¶
In this example we remove some data before sending it to Unomi:
<script>
window.dsdc = window.dsdc || function () { (dsdc.q = dsdc.q || []).push(arguments) }; dsdc.l = +new Date;
window.dsdc('beforeRequest', function (data) {
var changedCapture = data.requestData;
// make a change, eg. remove the cookies from capture
changedCapture.browserData.browser.dataCookies = {};
// use a global function to pass the modified capture back to the main script
dsdc.updateCapture(changedCapture);
});
</script>
Add day of the week to capture¶
In this example we add some data before sending it to Unomi:
<script>
window.dsdc = window.dsdc || function () { (dsdc.q = dsdc.q || []).push(arguments) }; dsdc.l = +new Date;
window.dsdc('beforeRequest', function (data) {
var changedCapture = data.requestData;
// make a change, eg. add the day of the week to the capture
var today = new Date();
changedCapture.te__dayOfWeek = today.toLocaleDateString("en-US", { weekday: 'long' });
// use a global function to pass the modified capture back to the main script
dsdc.updateCapture(changedCapture);
});
</script>
Add birthday with date of today to capture¶
In this example we add some data before sending it to Unomi:
<script>
window.dsdc = window.dsdc || function () { (dsdc.q = dsdc.q || []).push(arguments) }; dsdc.l = +new Date;
window.dsdc('beforeRequest', function (data) {
var changedCapture = data.requestData;
// make a change, eg. add today to the capture as birthday
changedCapture.da__birthday = (new Date()).toISOString();
// use a global function to pass the modified capture back to the main script
dsdc.updateCapture(changedCapture);
});
</script>
Read response AFTER capture is saved and sent to Unomi¶
In this example we read the data that was sent to Unomi:
<script>
window.dsdc = window.dsdc || function () { (dsdc.q = dsdc.q || []).push(arguments) }; dsdc.l = +new Date;
window.dsdc('afterResponse', function (data) {
// read the response data after the capture is sent to Unomi
console.log(data.responseData);
});
</script>
Prevent datacaptures¶
Prevent all data captures¶
In this example we prevent all captures being sent to Unomi:
<script>
window.dsdc = window.dsdc || function () { (dsdc.q = dsdc.q || []).push(arguments) }; dsdc.l = +new Date;
window.dsdc('preventCapture', true);
</script>
Prevent data captures for form submits only¶
In this example we prevent all form submits from being sent to Unomi:
<script>
window.dsdc = window.dsdc || function () { (dsdc.q = dsdc.q || []).push(arguments) }; dsdc.l = +new Date;
window.dsdc('preventCapture', true, 'formSubmit');
</script>
Prevent all data captures on Sundays¶
In this example we prevent all captures from being sent to Unomi on Sundays:
<script>
window.dsdc = window.dsdc || function () { (dsdc.q = dsdc.q || []).push(arguments) }; dsdc.l = +new Date;
var today = new Date();
if (today.getDay() == 0) {
window.dsdc('preventCapture', true);
}
</script>
Enable the js and load events, which are prevented by default¶
In this example we enable certain events to be sent to Unomi which are disabled by default:
<script>
window.dsdcSettings = window.dsdcSettings || {};
dsdcSettings.preventCapture = dsdcSettings.preventCapture || {};
// Set the preventCapture of these events to false
// This means they are no longer prevented
dsdcSettings.preventCapture.js = false;
dsdcSettings.preventCapture.load = false;
console.error(dsdcSettings);
</script>