initial port of heap code from DJ into sharelatex.

This commit is contained in:
Shane Kilkelly 2016-06-15 15:35:03 +01:00
parent e28e959941
commit 522ac8b59b
3 changed files with 19 additions and 1 deletions

View file

@ -48,6 +48,18 @@ html(itemscope, itemtype='http://schema.org/Product')
script(type='text/javascript').
window.ga = function() { console.log("Sending to GA", arguments) };
// Heap Analytics
if (settings.analytics.heap && session && session.user)
script(type="text/javascript").
window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var n=t.forceSSL||"https:"===document.location.protocol,a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=(n?"https:":"http:")+"//cdn.heapanalytics.com/js/heap-"+e+".js";var o=document.getElementsByTagName("script")[0];o.parentNode.insertBefore(a,o);for(var r=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["clearEventProperties","identify","setEventProperties","track","unsetEventProperty"],c=0;c<p.length;c++)heap[p[c]]=r(p[c])};
heap.load("#{settings.analytics.heap.token}");
script(type="text/javascript").
heap.identify({
handle: "#{session.user._id}",
email: "#{session.user.email}",
})
// End Heap Analytics
script(type="text/javascript").
window.csrfToken = "#{csrfToken}";

View file

@ -42,3 +42,7 @@ footer.site-footer
else
| !{item.text}
li
a(href="https://heapanalytics.com/?utm_source=badge")
img(style="width:108px;height:41px" src="//heapanalytics.com/img/badgeLight.png" alt="Heap | Mobile and Web Analytics")

View file

@ -6,6 +6,9 @@ define [
return {
send: (category, action, label, value)->
ga('send', 'event', category, action, label, value)
event_name = "#{action}-#{category}"
if window?.heap and window?.heap?.track
window.heap?.track(event_name, {label: label, value: value})
}
@ -14,4 +17,3 @@ define [
href = $(e.target).attr("href")
if href?
ga('send', 'event', 'navigation', 'top menu bar', href)