Skip to content

Instantly share code, notes, and snippets.

@mbianchihr
Forked from epintos/mediumStoriesStats.js
Created July 12, 2019 07:09
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 mbianchihr/4ff047216d72db61bf527dceb24c49e6 to your computer and use it in GitHub Desktop.
Save mbianchihr/4ff047216d72db61bf527dceb24c49e6 to your computer and use it in GitHub Desktop.
Export Medium Stats Stores to CSV
// Run Inspector Console in chrome and copy and paste the following code in the /stats/stories view
function download(filename, text) {
var pom = document.createElement('a');
pom.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
pom.setAttribute('download', filename);
if (document.createEvent) {
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
pom.dispatchEvent(event);
}
else {
pom.click();
}
}
content = "";
rows = document.querySelectorAll(".sortableTable-row.js-statsTableRow")
rows.forEach(function(row) {
title = row.querySelectorAll(".sortableTable-title > a")[0].innerText
values = row.querySelectorAll(".sortableTable-value")
views = values[1].innerText
reads = values[2].innerText
readRatio = values[3].innerText
recommends = values[4].innerText
content += title + ";" + views + ";" + reads + ";" + readRatio + ";" + recommends + "\n"
});
download("medium-metrics-" + new Date().toISOString().slice(0, 10) + ".csv", content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment