Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ahomu/gas

Minimal helper for Google Analytics better tracking.
https://github.com/ahomu/gas

Last synced: about 1 month ago
JSON representation

Minimal helper for Google Analytics better tracking.

Awesome Lists containing this project

README

        

#gas.js - Google Analytics Shorthands

"gas.js" given html driven tracking support.

**this is beta!**

##Feature

+ You can use a custom data attribute in the event tracking.
+ Auto track the outbound link as an event.
+ Maybe works on IE6~, Fx3.6~, Safari, Chrome, Opera
+ Automatically load the "ga.js". (throuth script element)
+ 2kb to minimize. (without ie compatibility then 1.7kb)
+ Not dependent on any library.

##Usage

hmm...

###Put


...

new GAS('UA-xxxxxxx-xx');
...

###Event tracking

// original
Done

// gas.js
Done

###Fake pageview tracking

// original
Fake page

// gas.js
Fake page

###Outbound link

External link

###API

var gas = new GAS('UA-xxxxxxx-xx');

// track as a pageview
gas.trackPageview('/your_optional_path.html');

// track as an event
gas.trackEvent('MusicPlayer', 'start', 'hogehoge');

###for IE

This is anchor element.

Action

For example, bind a click event using jQuery.

$('#clickable').bind('click', function() {
...

return false;
});

This 'click event' does not follow the 'document' and cannot event tracking. on Internet Explorer 6~8.

Solve this problem embed the following script, and class 'gas_prior' add to anchor element.


var gas = new GAS('UA-xxxxxxx-x');
jQuery(function() {
$('#clickable').bind('click', function(e) {
return false;
});

// need DOM has been loaded
gas.priorityOver('gas_prior');
});

Action

gas.priorityOver method re-binding event to each element with class 'gas_prior'.

##ToDo

えいごあやしいすみませんすみません

+ popstate, hashchange時のトラッキングサポート
+ 子要素clickへの反応(parentNodeを辿ってdata-xxxを探索する)

↓のようなdata属性の付与の仕方に対応したり


Start
Stop
Fav

##License

gas.js is licensed under the MIT licnese.