mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
fix(analytics): Pass tests
Restores the "UUID" property so that tests no longer fail. Corrects various typos in analytics service test. Moves landing page tracking to the Jade file to avoid duplicate tracking.
This commit is contained in:
@@ -26,13 +26,13 @@ describe('Analytics Service', function () {
|
||||
sandbox.stub(window, 'ga');
|
||||
});
|
||||
|
||||
it('sets up user with amplitude', function() {
|
||||
it('sets up user with Amplitude', function() {
|
||||
analytics.register();
|
||||
expect(amplitude.setUserId).to.have.been.calledOnce;
|
||||
expect(amplitude.setUserId).to.have.been.calledWith(user._id);
|
||||
});
|
||||
|
||||
it('sets up user with google analytics', function() {
|
||||
it('sets up user with Google Analytics', function() {
|
||||
analytics.register();
|
||||
expect(ga).to.have.been.calledOnce;
|
||||
expect(ga).to.have.been.calledWith('set', {userId: user._id});
|
||||
@@ -68,9 +68,9 @@ describe('Analytics Service', function () {
|
||||
sandbox.stub(window, 'ga');
|
||||
});
|
||||
|
||||
context('succeful tracking', function() {
|
||||
context('successful tracking', function() {
|
||||
|
||||
it('tracks a simple user action with amplitude', function() {
|
||||
it('tracks a simple user action with Amplitude', function() {
|
||||
var properties = {'hitType':'event','eventCategory':'behavior','eventAction':'cron'};
|
||||
analytics.track(properties);
|
||||
|
||||
@@ -78,7 +78,7 @@ describe('Analytics Service', function () {
|
||||
expect(amplitude.logEvent).to.have.been.calledWith('cron', properties);
|
||||
});
|
||||
|
||||
it('tracks a simple user action with google analytics', function() {
|
||||
it('tracks a simple user action with Google Analytics', function() {
|
||||
var properties = {'hitType':'event','eventCategory':'behavior','eventAction':'cron'};
|
||||
analytics.track(properties);
|
||||
|
||||
@@ -86,7 +86,7 @@ describe('Analytics Service', function () {
|
||||
expect(ga).to.have.been.calledWith('send', properties);
|
||||
});
|
||||
|
||||
it('tracks a user action with additional properties in amplitude', function() {
|
||||
it('tracks a user action with additional properties in Amplitude', function() {
|
||||
var properties = {'hitType':'event','eventCategory':'behavior','eventAction':'cron','booleanProperty':true,'numericProperty':17,'stringProperty':'bagel'};
|
||||
analytics.track(properties);
|
||||
|
||||
@@ -103,13 +103,13 @@ describe('Analytics Service', function () {
|
||||
});
|
||||
});
|
||||
|
||||
context('unsuccesful tracking', function() {
|
||||
context('unsuccessful tracking', function() {
|
||||
|
||||
beforeEach(function() {
|
||||
sandbox.stub(console, 'log');
|
||||
});
|
||||
|
||||
context('events without requird properties', function() {
|
||||
context('events without required properties', function() {
|
||||
beforeEach(function(){
|
||||
analytics.track('action');
|
||||
analytics.track({'hitType':'pageview','eventCategory':'green'});
|
||||
@@ -124,11 +124,11 @@ describe('Analytics Service', function () {
|
||||
expect(console.log.callCount).to.eql(7);
|
||||
});
|
||||
|
||||
it('does not call out to amplitude', function() {
|
||||
it('does not call out to Amplitude', function() {
|
||||
expect(amplitude.logEvent).to.not.be.called;
|
||||
});
|
||||
|
||||
it('does not call out to google analytics', function() {
|
||||
it('does not call out to Google Analytics', function() {
|
||||
expect(ga).to.not.be.called;
|
||||
});
|
||||
});
|
||||
@@ -142,11 +142,11 @@ describe('Analytics Service', function () {
|
||||
expect(console.log).to.have.been.calledOnce;
|
||||
});
|
||||
|
||||
it('does not call out to amplitude', function() {
|
||||
it('does not call out to Amplitude', function() {
|
||||
expect(amplitude.logEvent).to.not.be.called;
|
||||
});
|
||||
|
||||
it('does not call out to google analytics', function() {
|
||||
it('does not call out to Google Analytics', function() {
|
||||
expect(ga).to.not.be.called;
|
||||
});
|
||||
});
|
||||
@@ -183,12 +183,12 @@ describe('Analytics Service', function () {
|
||||
analytics.updateUser(properties);
|
||||
});
|
||||
|
||||
it('calls amplitude with provided properties and select user info', function() {
|
||||
it('calls Amplitude with provided properties and select user info', function() {
|
||||
expect(amplitude.setUserProperties).to.have.been.calledOnce;
|
||||
expect(amplitude.setUserProperties).to.have.been.calledWith(expectedProperties);
|
||||
});
|
||||
|
||||
it('calls google analytics with provided properties and select user info', function() {
|
||||
it('calls Google Analytics with provided properties and select user info', function() {
|
||||
expect(ga).to.have.been.calledOnce;
|
||||
expect(ga).to.have.been.calledWith('set', expectedProperties);
|
||||
});
|
||||
@@ -221,12 +221,12 @@ describe('Analytics Service', function () {
|
||||
analytics.updateUser();
|
||||
});
|
||||
|
||||
it('calls amplitude with select user info', function() {
|
||||
it('calls Amplitude with select user info', function() {
|
||||
expect(amplitude.setUserProperties).to.have.been.calledOnce;
|
||||
expect(amplitude.setUserProperties).to.have.been.calledWith(expectedProperties);
|
||||
});
|
||||
|
||||
it('calls google analytics with select user info', function() {
|
||||
it('calls Google Analytics with select user info', function() {
|
||||
expect(ga).to.have.been.calledOnce;
|
||||
expect(ga).to.have.been.calledWith('set', expectedProperties);
|
||||
});
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
angular.module('habitrpg')
|
||||
.controller("AuthCtrl", ['$scope', '$rootScope', 'User', '$http', '$location', '$window','ApiUrl', '$modal', 'Analytics',
|
||||
function($scope, $rootScope, User, $http, $location, $window, ApiUrl, $modal, Analytics) {
|
||||
|
||||
Analytics.track({'hitType':'pageview','eventCategory':'page','eventAction':'landing page','page':'/static/front'});
|
||||
$scope.Analytics = Analytics;
|
||||
|
||||
$scope.logout = function() {
|
||||
localStorage.clear();
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
}
|
||||
|
||||
function _gatherUserStats(user, properties) {
|
||||
if (user._id) properties.user_id = user._id;
|
||||
if (user._id) properties.UUID = user._id;
|
||||
if (user.stats) {
|
||||
properties.Class = user.stats.class;
|
||||
properties.Experience = Math.floor(user.stats.exp);
|
||||
|
||||
@@ -39,6 +39,7 @@ html(ng-app='habitrpg', ng-controller='RootCtrl')
|
||||
include ../shared/mixins
|
||||
include ../shared/modals/members
|
||||
.mobile-container
|
||||
div(ng-init='Analytics.track({"hitType":"pageview","eventCategory":"page","eventAction":"landing page","page":"/static/front"});')
|
||||
header#header
|
||||
nav.navbar.navbar-default.navbar-static-top
|
||||
.container-fluid
|
||||
|
||||
Reference in New Issue
Block a user