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.
| " ========================================================== | |
| " Vundle | |
| " ========================================================== | |
| set nocompatible | |
| filetype off | |
| set rtp+=~/.vim/bundle/vundle/ | |
| call vundle#rc() | |
| " let Vundle manage Vundle |
| (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){ |
| /** | |
| * Cross Browser helper to addEventListener. | |
| * | |
| * @param {HTMLElement} obj The Element to attach event to. | |
| * @param {string} evt The event that will trigger the binded function. | |
| * @param {function(event)} fnc The function to bind to the element. | |
| * @return {boolean} true if it was successfuly binded. | |
| */ | |
| var cb_addEventListener = function(obj, evt, fnc) { | |
| // W3C model |
As of April 2016. (Next month this list might be completely different.)
Ispired by:
| 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']); |
| var User = makeClass(); | |
| User.prototype.init = function(first, last){ | |
| this.name = first + " " + last; | |
| }; | |
| var user = User("John", "Resig"); | |
| user.name | |
| // => "John Resig" | |
| python2 -m SimpleHTTPServer |
| /** | |
| * 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 + ';'; |
| <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); |