Created
September 8, 2016 13:37
-
-
Save engagedcount/1487b1df564841fa0472c6c0cf5fefb5 to your computer and use it in GitHub Desktop.
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
jQuery.engagedCount = function(url, fn) { | |
url = encodeURIComponent(url || location.href); | |
var domain = "https://engagedcount.com"; | |
var apikey = "YOUR API KEY"; | |
var arg = { | |
data: { | |
url: url, | |
apikey: apikey | |
}, | |
url: domain + "/api", | |
cache: true, | |
dataType: "json" | |
}; | |
if ('withCredentials' in new XMLHttpRequest) { | |
arg.success = fn; | |
} else { | |
var cb = "ec_" + url.replace(/\W/g, ''); | |
window[cb] = fn; | |
arg.jsonpCallback = cb; | |
arg.dataType += "p"; | |
} | |
return jQuery.ajax(arg); | |
}; | |
$.engagedCount(location.href, function(data){ | |
console.log(data.Facebook.total_count); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment