Created
February 3, 2014 09:02
-
-
Save brettcave/8780766 to your computer and use it in GitHub Desktop.
nodejs kissmetrics export to import converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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