JoelPeterson

Home | Blog | Fundraiser Mailing List

Putting down the things I Pick up

Tips and Tricks I have gathered in web development

Tweet

Using hitCallback in Google Analytics with ga.js

By Joel Peterson on February 25, 2013

I recently ran into an interesting issue in Google Analytics – I wanted to track an event and then immediately direct the browser to a different page.  Easy right?
The problem was when the event tracking was implemented like this…

_gaq.push(['_trackEvent', 'Category', 'event', 'value']);
document.location = 'someOtherPage.html';

…the event call to Google Analytics was cancelled by the browser navigating away from the page before the event could be registered.

What I need here is a callback function that fires after the event has been registered. Google is providing this functionality in their new version of Analytics which is currently in beta.

But how could I incorporate this function using ga.js?

A little poking around led me to this answer in which flu describes how to use the above mentioned ‘hitCallback’ in ga.js.

Using flu’s answer as a starting point I found this code worked well:

_gaq.push(['_set','hitCallback',function(){
     document.location='someOtherPage.html';	
}]);
_gaq.push(['_trackEvent', 'Category', 'event', 'value']);

One last thing to consider at this point – now the browser navigation function is reliant on the Google Analytics object to be present. It would probably be a good idea to check the availability of GA and account for folks who have blocked it or otherwise don’t have the object available.

Something like the following should produce the desired result:

var callbackFunction = function(){
  document.location=someOtherPage.html;	
}
if(window._gat){
_gaq.push(['_set','hitCallback',callbackFunction]);
_gaq.push(['_trackEvent', 'Category', 'event', 'value']);
} else {
  callbackFunction();	
}

Posted in Analytics, Google Analytics, Javascript, Tips & Tricks | Tagged GA, google, Google Analytics, tracking | Leave a response

Tweet

2013 50/50 Boxpool Fundraiser Wrap Up

By Joel Peterson on February 15, 2013

Thanks to everyone who made the 2013 50/50 Boxpool Fundraiser a huge success!  With your help we were able to sell all 100 boxes and raise $1,500 for Hurricane Sandy relief efforts.

Congratulations to the winners

  • First Quarter – S. Khan
  • Half – S. Dilkes
  • Third Quarter – J. O’Briant
  • End of Game – T. Mauseth

How you helped Staten Island in their relief effort

A huge thanks to Mike Hassell for coordinating with Occupy Sandy in Staten Island to purchase the most needed items off of the Amazon wishlist. Here’s what was purchased:

Qty Description Price Total
1 “DEWALT Bare-Tool DC330B 18-Volt Cordless Jig Saw with Keyless Blade Change” $117.05 $117.05
1 “Shop-Vac 9633400 6.5-Peak HP Ultra Pro Series 12-Gallon Wet or Dry Vacuum with Detachable Blower” $138.18 $138.18
10 “Energizer Trail Finder 7 LED Headlight, Blue/Black, 3AAA Batteries Included” $16.26 $162.60
6 “3M 6297PA1-A Tekk Protection Mold and Lead Particle Respirator, Medium” $21.87 $131.22
1 “Shop-Vac 1032000 Mighty Mini Air Mover” $69.98 $69.98
1 “DEWALT Bare-Tool DC390B 6-1/2-Inch 18-Volt Cordless Circular Saw” $84.23 $84.23
1 “DEWALT DW1956 Pilot Point 16-Piece Twist Drill Bit Assortment” $25.56 $25.56
3 “Florida Coast 44-1428XL Superpolymer Premium Disposable Coveralls – One Size Fits All” $10.99 $32.97
1 “DEWALT DC970K-2 18-Volt Drill/Driver Kit” $114.99 $114.99
1 “Heavy-Duty, Rugged Dehumidifier OASIS D-165T” $449.00 $449.00
Subtotal $1325.78
Tax $69.09
S&H $110.75
Grand Total   $1505.62

Posted in Fundraiser | Tagged Mike Hassell, Occupy Sandy | Leave a response

Tweet

Extending jQuery’s slideToggle() Fading Absolutely Positioned Children

By Joel Peterson on January 28, 2013

jQuery’s native slideToggle function generates an undesirable effect when applied to a DOM element containing absolutely positioned children landing on or outside the parent’s boundaries.  At the outset of the animation jQuery hides the overflow of the animating element.  This will appear to”snap off” or “clip” any portion of any child element hanging outside of the borders of the parent.

Check out a working example of the undesirable effect here: http://jsfiddle.net/LFer9/.

As you can see as soon as the animation starts the overlay of the element becomes hidden – appearing to cut off the portion of the absolutely positioned elements which land outside the boundaries of the parent.

slideToggle clips children

To handle this issue more gracefully I’ve written a slideToggle extension which checks for offending children and quickly fade them out before commencing the sliding effect.

The result is a bit less jarring. See an example with the slideToggle extension here: http://jsfiddle.net/LFer9/1/

The source of the slideToggle extension can be found at https://github.com/joelasonian/slideToggleFadeOverlays.

 

Posted in Javascript, jQuery, plugins, Tips & Tricks | Tagged DOM, jQuery | Leave a response

Tweet

jQuery Event Namespacing

By Joel Peterson on July 10, 2012

Today I ventured into the land of namespaced events in jQuery.  I required the ability to remove a specific click event bound to an element without unbinding all of the element’s click events.

A little digging brought me to an excellent answer on stackoverflow and looking into the jQuery Documentation for on() I found:

An event name can be qualified by event namespaces that simplify removing or triggering the event. For example, “click.myPlugin.simple” defines both the myPlugin and simple namespaces for this particular click event. A click event handler attached via that string could be removed with .off(“click.myPlugin”) or .off(“click.simple”) without disturbing other click handlers attached to the elements.

That’s pretty sick.  Let’s try it.

First a couple of HTML buttons


The jQuery

$(document).ready(function(){
	$("#button").on("click", function(){ //not namespaced
		console.log('generic click');	
	});
	//namespace an event by appending a "." + string value to the action
	$("#button").on("click.myAction",function(){ 
		console.log('myAction namespace');	
	})
	$("#removeAction").on("click",function(){
		$("#button").off("click.myAction");  // remove the myAction event from #button
		console.log('myAction removed!!');
	});	
});

Resulting in..

  • Upon loading this script in the browser the “click this” button will log ‘generic click’ and ‘myAction namespace’ to the console.
  • Clicking the “Remove myAction Namespace” removes the myAction namespace and logs ‘myAction removed!!’.
  • All further clicks on the “click this” button will result in only logging ‘generic click’.

Posted in jQuery, Tips & Tricks | Tagged events, HTML, jQuery, namespacing | Leave a response

Tweet

Google Analytics Goal Conversions De-Dupe on Session

By Joel Peterson on June 29, 2012

Yesterday I discovered that the goal conversions in Google Analytics de-dupe on the user’s session.

The goal we set up to test was a URL destination goal type with a required step in the Goal Funnel.  We required case sensitive, exact matching URLS to count for conversion success.

We set up a test in which we created 10 unique users with email addresses.    We split the list into three sections and three people completed the funnel for each test goal in their list.   Each tester used a different browser for each test user.

Tester 1 Tester 2 Tester 3
Goal 1 – Chrome Goal 4 – Chrome Goal 8 – Chrome
Goal 2 – IE Goal 5 – IE Goal 9 – IE
Goal 3 – Firefox Goal 6 – Firefox Goal 10 – Firefox
Goal 7 – safari

The original purpose of our testing was to understand how duplications were being handled across our various conversion tracking and lead generation platforms.  With that in mind we filled out the goals again.  In our effort to ensure no duplicate data Tester 2 took Tester 1′s test users,  Tester 3 took Tester 2′s, and Tester1 took Tester 3′s.

Resulting in the following:

Tester 1 Tester 2 Tester 3
Goal 8 – Chrome Goal 1 – Chrome Goal 4 – Chrome
Goal 9 – IE Goal 2 – IE Goal 5 – IE (browser re-opened)
Goal 10 – Firefox Goal 3 – Firefox Goal 6 – Firefox
Goal 7 – safari

One thing to note:  On the second round of tests – Tester 3 closed his Internet Explorer before running Goal 5.  Other than that one browser session…  all other browsers remained opened through both rounds of testing.

Guess how many conversion there were.

Test Form Completed: 12

Personally I had expected to see either the number 10 or 20.  Not 12.    But after thinking about it – 12 is the number you derive if you de-dupe on the user’s session.

Green = Counted Goal

Red = Duplicate on Session

Tester 1 – round 1 Tester 2 – round 1 Tester 3 – round 1
Goal 1 – Chrome Goal 4 – Chrome Goal 8 – Chrome
Goal 2 – IE Goal 5 – IE Goal 9 – IE
Goal 3 – Firefox Goal 6 – Firefox Goal 10 – Firefox
Goal 7 – safari
Tester 1 – round 2 Tester 2 – round 2 Tester 3 – round 2
Goal 8 – Chrome Goal 1 – Chrome Goal 4 – Chrome
Goal 9 – IE Goal 2 – IE Goal 5 – IE (browser re-opened)
Goal 10 – Firefox Goal 3 – Firefox Goal 6 – Firefox
Goal 7 – safari

De-duping on user’s session we can see there were 12 goal conversions.

Posted in Tips & Tricks | Tagged analytics, conversions, Goal Funnel, google, Google Analytics, session, tracking, URL | 2 Responses

Next »
Thanks for scrolling all the way down here! Want more? Catch me on Twitter, FourSquare, Delicious, LinkedIn and My RSS Feed