diff --git a/lib/controller/auth-form.js b/lib/controller/auth-form.js index a80397a85..2d22ac0c1 100644 --- a/lib/controller/auth-form.js +++ b/lib/controller/auth-form.js @@ -6,7 +6,7 @@ */ var app = require('../app'), - tracking = require('../core/tracking'); + analytics = require('../core/analytics'); app.controller('AuthController', ['$scope', '$rootScope', '$element', 'API', 'AUTH', function ($scope, $rootScope, $element, api, auth) { var loginForm = $element.find('kano-login-form')[0], @@ -28,7 +28,7 @@ app.controller('AuthController', ['$scope', '$rootScope', '$element', 'API', 'AU $scope.onLoginSuccess = function (ev) { var user = ev.details.user; - tracking.event('Login success', { + analytics.track('Login success', { id: user.id, email: user.email, username: user.username @@ -37,7 +37,7 @@ app.controller('AuthController', ['$scope', '$rootScope', '$element', 'API', 'AU $scope.onSignupSuccess = function (ev) { var user = ev.details.user; - tracking.event('Registration Completed', { + analytics.track('Registration Completed', { username: user.username }); }; diff --git a/lib/core/analytics.js b/lib/core/analytics.js index 7e81d811a..9574ebb45 100644 --- a/lib/core/analytics.js +++ b/lib/core/analytics.js @@ -1,25 +1,16 @@ -var config = window.CONFIG, - analytics = window.analytics; - /* * Analytics module - * - * Wrapper to Segment.io analytics - * More documentation at: https://segment.com/docs/libraries/analytics.js - */ - -var enabled = config.SEGMENTIO_ID && !config.OFFLINE && analytics; + * Currently we are using Google Analytics with Google Tag Manager +*/ /* - * Initialise Segment.io if `SEGMENTIO_ID` is present in config, start + * Initialise start * tracking page views * * @return void */ exports.init = function () { - if (!enabled) { return; } - - window.analytics.load(config.SEGMENTIO_ID); + return; }; /* @@ -29,9 +20,15 @@ exports.init = function () { * @return void */ exports.page = function (pageId) { - if (!enabled) { return; } + if (!pageId) { + return; + } - window.analytics.page(pageId); + dataLayer.push({ + 'event' : 'virtualPageView', + 'virtualPageTitle' : document.title, + 'virtualPageURL' : pageId + }); }; /* @@ -48,9 +45,8 @@ exports.page = function (pageId) { * @return void */ exports.identify = function (userId, traits, options, callback) { - if (!enabled) { return; } - - window.analytics.identify(userId, traits, options, callback); + // Not used - switched to GA + return; }; /* @@ -65,7 +61,6 @@ exports.identify = function (userId, traits, options, callback) { * @return void */ exports.track = function (event, properties, options, callback) { - if (!enabled) { return; } - - window.analytics.track(event, properties, options, callback); + // Not used - switched to GA + return; }; diff --git a/lib/core/auth.js b/lib/core/auth.js index 67535c7db..34e76050b 100644 --- a/lib/core/auth.js +++ b/lib/core/auth.js @@ -6,7 +6,7 @@ var api, user = null, - tracking = require('./tracking'); + analytics = require('./analytics'); /* * Get user object if logged in @@ -49,7 +49,7 @@ function auth (config) { user = session.user; }, logout : function () { - tracking.event('Logout', { + analytics.track('Logout', { user: { id : user.id, username : user.username, diff --git a/lib/core/tracking.js b/lib/core/tracking.js deleted file mode 100644 index b930b3a09..000000000 --- a/lib/core/tracking.js +++ /dev/null @@ -1,48 +0,0 @@ -'use strict'; - -/* - * Tracking module - * - * Centralised tracking module that provides an interface to track event and - * manages the communication with whatever tracking system is currently in use - * (At the moment Segment.io) - * - * This module provides a unified interface of communicating events that - * allowed us to easily witch and try out different analytics third-party - * services and APIs - * - * NOTE: The `window.analytics` Object is provided by the Segment.io library - */ -var config = require('./config'), - analytics = window.analytics || null, - key = config.SEGMENTIO_ID, - enabled = key && analytics; - -/* - * Initialise module Initialise Segment.io with key from the config module - */ -function init() { - if (!enabled) { - return; - } - - analytics.load(key); - -} - -/* - * track event with given arguments - * @param {*..=} - */ -function event() { - if (!enabled) { - return; - } - - analytics.track.apply(analytics, arguments); -} - -module.exports = { - init : init, - event : event -}; diff --git a/views/index.jade b/views/index.jade index 94a70e54e..2cff86ac2 100644 --- a/views/index.jade +++ b/views/index.jade @@ -14,6 +14,7 @@ html(lang='en', xmlns:ng="http://angularjs.org") link(href='/css/main.css', rel='stylesheet', type='text/css') script(type="text/javascript"). + var dataLayer = []; (function() { window.XMLHttpRequest = window.XMLHttpRequest || (function() { return new window.ActiveXObject("Microsoft.XMLHTTP"); @@ -24,16 +25,7 @@ html(lang='en', xmlns:ng="http://angularjs.org") script(src='/js/vendor/xtag.js') body(id="ng-app", ng-app='draw', class=offline ? 'offline' : 'online') - //- Google Tag Manager - noscript - iframe(src='//www.googletagmanager.com/ns.html?id=GTM-WMGKFR', height='0', width='0', style='display: none; visibility: hidden;') - script(type='text/javascript'). - (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': - new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], - j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= - '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); - })(window,document,'script','dataLayer','GTM-WMGKFR'); - //- End Google Tag Manager + script(src='/js/vendor/console-polyfill.js', type='text/javascript') .loading-overlay(ng-cloak): .spinner @@ -78,3 +70,14 @@ html(lang='en', xmlns:ng="http://angularjs.org") //- Livereload if !production script(src='http://localhost:35729/livereload.js?snipver=1', type='text/javascript') + + //- Google Tag Manager + noscript + iframe(src='//www.googletagmanager.com/ns.html?id=GTM-WMGKFR', height='0', width='0', style='display: none; visibility: hidden;') + script(type='text/javascript'). + (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': + new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], + j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= + '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); + })(window,document,'script','dataLayer','GTM-WMGKFR'); + //- End Google Tag Manager