By Erik Vold
—
Last update
Jul 11, 2008
—
Installed
77 times.
// ==UserScript==
// @name Add Digg Count to Google Analytics
// @namespace addDiggToGA
// @include https://www.google.com/analytics/reporting/content_detail?*
// @version 1.0
// @description This will display the digg count of a page in google analytics.
// ==/UserScript==
try{
var tempStr = "http://io9.com/5022295/five-signs-the-united-states-is-withering-away";
var addDiggToGA = {};
addDiggToGA.pageURL = "";
addDiggToGA.numberOfDiggs = "?";
addDiggToGA.tempDiv = document.createElement('div');
addDiggToGA.tempDiv.style.display = "none";
addDiggToGA.newDisplayDiv = document.createElement('div');
addDiggToGA.pageURL = document.getElementById('ControlBar').getElementsByTagName('a')[0].href;
GM_xmlhttpRequest({
method: 'GET',
url: 'http://digg.com/tools/diggthis.php?u='+addDiggToGA.pageURL,
headers: {
'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
'Accept': 'application/atom+xml,application/xml,text/xml',
},
onload: function(responseDetails) {
/*
alert('Request for Atom feed returned ' + responseDetails.status +
' ' + responseDetails.statusText + '\n\n' +
'Feed data:\n' + responseDetails.responseText);
*/
addDiggToGA.numberOfDiggs = responseDetails.responseText.match(/<li class="digg-count"[^>]*>([^<]|<[^\/]|<\/[^l]|<\/l[^i]|<\/li\s*[^>])*<\/li\s*>/);
addDiggToGA.tempDiv.innerHTML = addDiggToGA.numberOfDiggs;
addDiggToGA.numberOfDiggs = addDiggToGA.tempDiv.getElementsByTagName('strong')[0].innerHTML;
if( addDiggToGA.numberOfDiggs == "Digg" ){
addDiggToGA.numberOfDiggs = 0;
}
else{
addDiggToGA.numberOfDiggs = addDiggToGA.numberOfDiggs.match(/\d*/);
if( addDiggToGA.numberOfDiggs == "" ){
addDiggToGA.numberOfDiggs = 0;
}
}
addDiggToGA.newDisplayDiv.innerHTML = "<div>"+
"<div class='sparkline'>"+
"<div>"+
"<div class='visualization'>"+
"<img src='http://www.feedm8.com/web/images/logos/digg.gif' border='0' />"+
"</div>"+
"</div>"+
"<div>"+
"<div class='statistic'>"+
"<h3>"+
"<span class='primary_value'>" + addDiggToGA.numberOfDiggs + " </span>"+
"<span class='label'> Total Digg(s)</span>"+
"</h3>"+
"</div>"+
"</div>"+
"</div>"+
"</div>";
document.getElementById('PageviewsSparkline').parentNode.parentNode.parentNode.appendChild( addDiggToGA.newDisplayDiv );
}
});
}
catch(e){};