Converting a custom processor written for V1 to work in V2 is straightforward. Let's compare the the Mixpanel processor written for the request processing documentation in V1 and V2:
- Mixpanel Processor V1
(function() {
try {
window.diver.processors.mixpanel = {
name: 'Mixpanel',
namespace: 'mixpanel',
process: function process(traffic) {
var params;
var obj;
traffic.request.queryString.some(({name, value}) => {
if (name === 'data') {
params = decodeURIComponent(value);
return true;
}
});
if (!params) {
return {};
}
try {
obj = JSON.parse(atob(params));
} catch (e) {
obj = {};
}
obj.properties.event = obj.event;
return obj.properties;
}
};
} catch (e) {}
})();
- Mixpanel Processor V2
function getProcessor() {
return {
name: 'Mixpanel',
namespace: 'mixpanel',
process: function process(traffic) {
var params;
var obj;
traffic.request.queryString.some(({name, value}) => {
if (name === 'data') {
params = decodeURIComponent(value);
return true;
}
});
if (!params) {
return {};
}
try {
obj = JSON.parse(atob(params));
} catch (e) {
obj = {};
}
obj.properties.event = obj.event;
return obj.properties;
}
};
}
To put it in words, in V2:
- The processor is represented as a
getProcessor
function. - The object that was assigned to a namespaced variable
window.diver.processors
in V1 is now returned in thegetProcessor
function. - There is no need to worry about catching errors thrown by the processor as the extension will handle them.