Skip to content

Instantly share code, notes, and snippets.

@engagedcount
Created September 8, 2016 13:37
Show Gist options
  • Save engagedcount/1487b1df564841fa0472c6c0cf5fefb5 to your computer and use it in GitHub Desktop.
Save engagedcount/1487b1df564841fa0472c6c0cf5fefb5 to your computer and use it in GitHub Desktop.
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