app/scripts/plugins/analytics.coffee

EPFL analytics plugin

Handle Google analytics registration

requires: jQuery or Zepto DOM library author: Julien Ramboz version: 1.0

AMD loader

Try loading as AMD module or fall back to default loading

((plugin) -> if typeof define is "function" and define.amd define ["jslib", "header"], plugin else plugin @$ ).call this, analytics = ($) -> "use strict" ((i, s, o, g, r, a, m) -> i["GoogleAnalyticsObject"] = r i[r] = i[r] or -> (i[r].q = i[r].q or []).push arguments return i[r].l = 1 * new Date() a = s.createElement(o) m = s.getElementsByTagName(o)[0] a.async = 1 a.src = g m.parentNode.insertBefore a, m return ) window, document, "script", "//www.google-analytics.com/analytics.js", "ga" $ ->

Init EPFL tracker

ga "create", "UA-4833294-1", {"name": "epfl", "cookieDomain": "auto"} ga "epfl.set", "anonymizeIp", true ga "epfl.send", "pageview"

Global navigation clicks

$("#epfl-header").on "click", ".epflnav .nav-link", (e) -> ga "epfl.send", "event", "Global Nav", "Show Pane", e.currentTarget.id $("#epfl-header").on "click", ".pane a", (e) -> ga "epfl.send", "event", "Global Nav", "Click", e.target.href

Toolbar clicks

$("#tools .share-link").on "click", (e) -> site = $.trim($(e.target).attr("class").replace("share-link")) ga "epfl.send", "social", site, "Share", window.location.href ga