Skip to content

Instantly share code, notes, and snippets.

@ivzhao
Last active January 3, 2020 13:19
Show Gist options
  • Save ivzhao/e161a0df1276995536923c18484d1e37 to your computer and use it in GitHub Desktop.
Save ivzhao/e161a0df1276995536923c18484d1e37 to your computer and use it in GitHub Desktop.
Get Intercom tags count from your browser
// Step 1. Turn on this Chrome plugin to disable Content Security Policy https://chrome.google.com/webstore/detail/disable-content-security/ieelmcmcagommplceebfedjlakkhpden?hl=en
// Step 2. Change your Intercom App Id below.
// Step 3. Go to your Intercom Tags page.
// Step 4. Copy/paste this script in your Chrome console, it will download a .csv file once it's completed.
// Step 5 (Optional) Sometimes you have to toggle the ORIGIN below between .io or .com.
// Your Intercom App Id
var INTERCOM_APP_ID = "REPLACE_WITH_YOUR_ID"
// Origin. Change between https://app.intercom.com or https://app.intercom.io
var ORIGIN = "https://app.intercom.com"
// Slow down the request to prevent Intercom from blocking you.
var TIMEOUT = 60
var tags = []
var ids = []
$("tbody").children().each(function(index, tr){
var tag = tr.children[1].textContent.trim()
var href = tr.children[6].children[0].getAttribute("href")
var id = href.replace("/a/apps/" + INTERCOM_APP_ID + "/respond/inbox/search?tag=", "")
tags.push(tag)
ids.push(id)
})
var counts = []
var currentIndex = 0
var getCount = function() {
var id = ids[currentIndex]
$.get(ORIGIN + "/ember/conversations/search.json?app_id=" + INTERCOM_APP_ID + "&sort_direction=desc&status=all&per_page=15&tag_ids%5B%5D=" + id).done(function(data){
var count = data.total_count
counts[currentIndex] = count
console.log(tags[currentIndex], count)
if (currentIndex < ids.length - 1) {
currentIndex += 1
setTimeout(getCount, TIMEOUT)
} else {
var result = _.map(_.zip(tags, counts), function(zipped){return zipped.join(", ")}).join("\n")
var blob = new Blob([result]);
$("<a>", {
download: "Count " + moment().format() + ".csv",
href: URL.createObjectURL(blob)
}).get(0).click()
}
})
}
getCount()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment