Skip to content

Instantly share code, notes, and snippets.

Avatar

Eduardo Cereto Carvalho eduardocereto

  • Google Inc
  • Los Angeles, CA
View GitHub Profile
@eduardocereto
eduardocereto / ga-track-outbound.js
Last active Aug 29, 2015
Outbound Link Tracking
View ga-track-outbound.js
(function(){
// Provides a plugin name and constructor function to analytics.js. This
// function works even if the site has customized the ga global identifier.
function _providePlugin(pluginName, pluginConstructor) {
var ga = window[window['GoogleAnalyticsObject'] || 'ga'];
if (ga) ga('provide', pluginName, pluginConstructor);
}
// Creates the plugin to tag outbound link
function outboundConstructor(tracker, config){
@eduardocereto
eduardocereto / README.md
Last active Aug 2, 2017
Calculates Traffic Source
View README.md

Calculates Traffic Source

Still a work in progress, not ready for usage.

Tries to mim Classic Google Analytics methodology to calculate traffic source client side.

On Universal Analytics all this is calculated server side, so it's unavailable in case you need it client side.

@eduardocereto
eduardocereto / analytics.js
Created Oct 2, 2012
GAS firing MaxScroll with sampling
View analytics.js
var _gas = _gas || [];
_gas.push(['_setAccount', 'UA-YYYYYY-Y']); // REPLACE WITH YOUR GA NUMBER
_gas.push(['_setDomainName', '.mydomain.com']); // REPLACE WITH YOUR DOMAIN
_gas.push(['_trackPageview']);
_gas.push(['_gasTrackForms']);
_gas.push(['_gasTrackOutboundLinks']);
// Max Scroll on 20% of the pages
if(Math.random() * 100 < 20) {
_gas.push(['_gasTrackMaxScroll']);
@eduardocereto
eduardocereto / .vimrc
Created Jul 11, 2012
.vimrc optimized for Python and Javascript
View .vimrc
" ==========================================================
" Vundle
" ==========================================================
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
@eduardocereto
eduardocereto / example.js
Created Jul 8, 2012
Simple Class Instantiation Javascript
View example.js
var User = makeClass();
User.prototype.init = function(first, last){
this.name = first + " " + last;
};
var user = User("John", "Resig");
user.name
// => "John Resig"
View python2-server.sh
python2 -m SimpleHTTPServer
@eduardocereto
eduardocereto / get_top_domain.js
Created Jul 3, 2012
Always return top level domain
View get_top_domain.js
/**
* First domain where cookies can be set by the browser.
*/
function get_top_domain(){
var i,h,
weird_cookie='__top_level=cookie',
hostname = document.location.hostname.split('.');
for(i=hostname.length-1; i>=0; i--) {
h = hostname.slice(i).join('.');
document.cookie = weird_cookie + ';domain=.' + h + ';';
@eduardocereto
eduardocereto / ga-addthis.html
Created Jun 7, 2012 — forked from googleanalyticsresoneo/ga-addthis.html
AddThis and Google Analytics integration
View ga-addthis.html
<script type="text/javascript">
// standard GA async code
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
@eduardocereto
eduardocereto / gist:2312353
Created Apr 5, 2012 — forked from anonymous/gist:2309745
Track Client-Side Errors with Google Analytics
View gist:2312353
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-12345678-1']);
_gaq.push(['_setDomainName', 'yoursite.com']);
_gaq.push(['_addIgnoredRef', 'yoursite.com']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;