Skip to content

Instantly share code, notes, and snippets.

@simondahla
simondahla / google-analytics-siteSpeedSampleRate.js
Last active August 4, 2018 17:45
Set proper Sample Rate for Site Speed http://blog.mythly.com/improve-site-speed-in-google-analytics/ Note: Google will automatically cap the sample rate to 10k pageviews a day.
_gaq.push(['_setSiteSpeedSampleRate', 100]);
@simondahla
simondahla / vwo-blink-prevention.css
Created October 22, 2013 11:49
How to prevent "the blink" in Visual Website Optimizer
/* Track 0 Serch Results with if statment */
var content = document.getElementById('middlewrapper');
if (content.innerHTML.search('Inga produkter hittades!')) {
var sn = "q";
var sr = new RegExp(sn+"=[^\&]+"),
p = document.location.pathname,
s = document.location.search,
sm = s.match(sr).toString(),

Track Searches with 0 Results in Universal Analytics

The code would look something like this (you will have to modify this so it will work on your site):

var searchQuery = $('input[class="rsearch_sok2"]').val();
var p = document.location.pathname;
var s = "/?q=" +  searchQuery + "&cat=no-results";
ga('send', 'pageview', {'page':p + s});
var startTime;function loadJs(url, callback) {  var js = document.createElement('script');  js.async = true;  js.src = url;  var s = document.getElementsByTagName('script')[0];  js.onload = trackTimingCallback;  startTime = new Date().getTime();  s.parentNode.insertBefore(js, s);}function trackTimingCallback(event) {  var endTime = new Date().getTime();  var timeSpent = endTime - startTime;  ga('send', 'timing', 'jQuery', 'Load Library', timeSpent, 'Google CDN');  // Library has loaded. Now you can use it.};
@simondahla
simondahla / CCG-VWO.md
Last active December 24, 2015 07:09
How to add a Custom Conversion Goal (CCG) in Visual Website Optimizer (VWO) for a specific test

#Custom Conversion Goal in Visual Website Optimizer (VWO)

How to add a Custom Conversion Goal (CCG) in VWO. Use this to be able to add a CCG for a specific test.

Replace goalId and testlId with your test specific values.

@simondahla
simondahla / app.js
Created September 20, 2013 21:26 — forked from JacerOmri/app.js
var restify = require('restify'),
mongoose = require('mongoose');
var server = restify.createServer({
name: 'mongo-api'
})
server.listen(7000, function () {
console.log('%s listening at %s', server.name, server.url)
})
db = mongoose.connect("mongodb://localhost/example-api");
@simondahla
simondahla / ga-ua-search-tracking-0-results.js
Last active May 2, 2019 18:50
For Universal Google Analytics - Tracking Search Results with 0 hits. Put this in the 0 results page template.
//Define your search query parameter as varible sn
var sn = "q";
var sr = new RegExp(sn+"=[^\&]+");
p = document.location.pathname;
s = document.location.search;
if (!!s.match(sr)) {
sm = s.match(sr).toString();
srs = sm.split("=");
// The next line is where we add the category and add
@simondahla
simondahla / jquery.link-tracking-ga.js
Last active September 27, 2019 17:03
Google Analytics Link Tracking For both GA Classic & GA UA
@simondahla
simondahla / jquery.iframetracker.js
Created July 30, 2013 11:32
Add Conversion Tracking to an iframe with VWO and iframetracker.js
/**
* jQuery iframe click tracking plugin demo
* Version 1.0 (2013-03-30)
* Copyright © 2013 Vincent Paré
* https://github.com/finalclap/iframeTracker-jquery
*/
(function($){
// Registering new tracking handler
$.fn.iframeTracker = function(handler){
// Storing the new handler into handler list