Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
nodejs kissmetrics export to import converter
var fs = require("fs"),
API_KEY = "MY_API_KEY";
function parseResults(filename) {
fs.readFile(filename, 'utf-8', function (err, fileContents) {
if (err) throw err;
var parsedJson = JSON.parse(fileContents);
for (element in parsedJson) {
var params = "?_k=" + API_KEY + "&_d=1"
// Default to the "set properties" endpoint....
var endPoint = "/s"
var obj = parsedJson[element]
for (key in obj) {
// If a _n key is present in the entry, then this is an event entry, not a set-property entry
if (key == "_n")
endPoint = "/e"
if (key == "_p1")
endPoint = "/a"
params += "&" + encodeURIComponent(key) + "=" + encodeURIComponent(obj[key])
}
// We could easily build an HTTP client call, but rather logging here and redirecting to an output file for later.
console.log("https://trk.kissmetrics.com" + endPoint + params)
}
});
}
parseResults(process.argv[2]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.