Skip to content

Instantly share code, notes, and snippets.

View eduardocereto's full-sized avatar
💩

Eduardo Cereto Carvalho eduardocereto

💩
View GitHub Profile
@eduardocereto
eduardocereto / ga-track-outbound.js
Last active July 16, 2022 17:19
Outbound Link Tracking
(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 August 2, 2017 15:12
Calculates Traffic Source

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 October 2, 2012 18:35
GAS firing MaxScroll with sampling
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 July 11, 2012 07:02
.vimrc optimized for Python and Javascript
" ==========================================================
" Vundle
" ==========================================================
set nocompatible
filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
@eduardocereto
eduardocereto / example.js
Created July 8, 2012 20:48
Simple Class Instantiation Javascript
var User = makeClass();
User.prototype.init = function(first, last){
this.name = first + " " + last;
};
var user = User("John", "Resig");
user.name
// => "John Resig"
@eduardocereto
eduardocereto / python2-server.sh
Created July 8, 2012 09:16
Simple Local Server
python2 -m SimpleHTTPServer
@eduardocereto
eduardocereto / get_top_domain.js
Created July 3, 2012 21:18
Always return top level domain
/**
* 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 June 7, 2012 08:59 — forked from googleanalyticsresoneo/ga-addthis.html
AddThis and Google Analytics integration
<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 April 5, 2012 16:29 — forked from anonymous/gist:2309745
Track Client-Side Errors with Google Analytics
<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;