Skip to content

Instantly share code, notes, and snippets.

@hito-asa
Created April 18, 2013 08:56
Show Gist options
  • Select an option

  • Save hito-asa/5411285 to your computer and use it in GitHub Desktop.

Select an option

Save hito-asa/5411285 to your computer and use it in GitHub Desktop.

Revisions

  1. Hitoshi Asai created this gist Apr 18, 2013.
    18 changes: 18 additions & 0 deletions google_analytics.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    var _gaq = _gaq || [];
    var pluginUrl = '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
    _gaq.push(['_require', 'inpage_linkid', pluginUrl]);
    <c:if test="${!gaq.suppressLogging}">
    _gaq.push(['_setAccount', '<%= GA_PROPERTY_ID %>']);
    _gaq.push(['_setSiteSpeedSampleRate', 30]);
    <c:forEach var="v" items="${gaq.customVars}" varStatus="status">_gaq.push(['_setCustomVar', ${f:h(v.index)}, '${f:h(v.name)}', '${f:h(v.value)}', ${f:h(v.scope.value)}]);</c:forEach>
    <c:choose>
    <c:when test="${gaq.customUrl != null}">_gaq.push(['_trackPageview', '<c:out value="${gaq.customUrl}" />']);</c:when>
    <c:otherwise>_gaq.push(['_trackPageview']);</c:otherwise>
    </c:choose>
    <c:forEach var="e" items="${gaq.events}" varStatus="status">_gaq.push(['_trackEvent', '${f:h(e.category)}', '${f:h(e.action)}', '${f:h(e.label)}', ${f:h(e.value)}, true]);</c:forEach>
    </c:if>
    (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);
    })();