Skip to content

Instantly share code, notes, and snippets.

Where is the average fold

Screen Resolution Visitor Avg. Min. Max.
1680x1050 (36%) 1508x845 582x623 1680x989
1440x900 (36%) 1354x752 704x549 1140x836
1600x900 (36%) 1485x741 963x410 1600x809
1920x1200 (36%) 1559x952 944x696 1920x1138
2560x1440 (36%) 1631x1109 966x697 2560x1342
var myElement = document.getElementById('IDoftheDIV');
if(window.addEventListener) {
// Normal browsers
myElement.addEventListener('DOMSubtreeModified', contentChanged, false);
} else
if(window.attachEvent) {
// IE
myElement.attachEvent('DOMSubtreeModified', contentChanged);
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i].trim();
if (c.indexOf(name)===0) return c.substring(name.length,c.length);
}
return "";
}
@simondahla
simondahla / track-js-error-with-google-analytics.js
Last active October 18, 2018 14:31
A Poor Man's Javascript Error Logger using Google Analytics
window.onerror = function(message, file, line) {
if (typeof(ga) !== "undefined") {
ga('send', 'event', 'Global', 'Exception', file + "(" + line + "): " + message);
}
};
@simondahla
simondahla / track-downloads-with-universal-google-analytics.js
Created January 16, 2014 17:42
Track, downloads, email, external link clicks with Universal Google Analytics. Include this at the bottom of the desired page. Note: Requiers jQuery to work, include jQuery above this script.
if (typeof jQuery != 'undefined') {
jQuery(document).ready(function($) {
var filetypes = /\.(zip|exe|pdf|doc*|xls*|ppt*|mp3)$/i;
var baseHref = '';
if (jQuery('base').attr('href') != undefined)
baseHref = jQuery('base').attr('href');
jQuery('a').each(function() {
var href = jQuery(this).attr('href');
if (href && (href.match(/^https?\:/i)) && (!href.match(document.domain))) {
jQuery(this).click(function() {
@simondahla
simondahla / advertising.js
Last active January 3, 2016 11:58
Google Analytics Retargeting and Demographics and Interests reports for AdWords and AdBlock software with regular (Google Analytics Classic) fallback.
/* Add this in the top of your advertising script */
_adblock = false;
if (typeof jQuery != 'undefined') {
jQuery(document).ready(function($) {
$('form input').blur(function( e ){
var me = $(this), form = me.parents('form');
ga('send', 'event', (me.attr('name') || me.attr('id')), (me.val().length > 0 ? 'filled' : 'empty'), $(this).attr('name')]));
});
}
}
var pixelRatio = (window.devicePixelRatio >= 1.5) ? "high" : "normal";
ga('send', 'pageview', {'dimension5': pixelRatio});
/*
Google Analytics Classic - Browser Viewport Size
Credit @beantin
CC BY 2.5 2013
*/
function viewport() {
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;