Skip to content

Instantly share code, notes, and snippets.

@brettcave
Created February 3, 2014 09:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brettcave/8780766 to your computer and use it in GitHub Desktop.
Save brettcave/8780766 to your computer and use it in GitHub Desktop.
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