Sending Custom Channel Data to Kissmetrics
In addition to the Channel traffic data that we collect and calculate automatically, you can send over a Custom Channel information as event with property via JS APIs. The following example captures values for a custom property called custom_channel
which are passed via a query-string parameter in the URL. This is a common practice when the user is coming from a different domain or when the user is clicking a link embedded in an email, and you’d like to track additional data once the user lands on your site.
I. Using Kissmetrics JS APIs
http://127.0.0.1:5500/index.html?custom_channel=unique
const params = new URL(location.href).searchParams;
const isTrackable = params.has("custom_channel");
const customChannel = params.get("custom_channel");
params.delete("custom_channel");
if (window._kmq && isTrackable && customChannel) {
window._kmq.push(["record","Custom traffic", //Custom traffic is an example event name, you are free to adjust it.
"custom channel": customChannel,
{
"custom channel": customChannel, //customChannel = unique from the URL
},
]);
} else {
console.error("Kissmetrics snippet not loaded or no required search params");
}
Result in Kissmetrics:
II. Using Segment's APIs
http://127.0.0.1:5500/index.html?custom_channel=unique
const params = new URL(location.href).searchParams;
const isSegmentTrackable = params.has("custom_channel");
const customChannel = params.get("custom_channel");
params.delete("custom_channel");
if (window.analytics) {
window.analytics.initialize({
KISSmetrics: {
apiKey: "<REDACTED>",
},
});
window.analytics.page();
if (isSegmentTrackable && customChannel) {
window.analytics.track("Segment traffic", { //Segment traffic is an example event name, you are free to adjust it.
"custom channel": customChannel, //customChannel = unique from the URL
});
}
} else {
console.error("Segment snippet not loaded");
}
Result in Kissmetrics:
Updated over 1 year ago