Revert "Revert Facebook Pixel" (#8449)

This commit is contained in:
Matteo Pagliazzi
2017-01-23 16:38:56 +01:00
committed by GitHub
parent 9a5d17f538
commit 74c6a891fc
5 changed files with 53 additions and 18 deletions

View File

@@ -26,22 +26,14 @@ describe('Analytics Service', function () {
describe('register', function() {
beforeEach(function() {
sandbox.stub(amplitude, 'setUserId');
sandbox.stub(window, 'ga');
sandbox.stub(window, 'fbq');
});
it('sets up user with Amplitude', function() {
it('records a registration event on Facebook', function() {
analytics.register();
clock.tick();
expect(amplitude.setUserId).to.have.been.calledOnce;
expect(amplitude.setUserId).to.have.been.calledWith(user._id);
});
it('sets up user with Google Analytics', function() {
analytics.register();
clock.tick();
expect(ga).to.have.been.calledOnce;
expect(ga).to.have.been.calledWith('set', {userId: user._id});
expect(fbq).to.have.been.calledOnce;
expect(fbq).to.have.been.calledWith('track', 'CompleteRegistration');
});
});
@@ -74,6 +66,7 @@ describe('Analytics Service', function () {
beforeEach(function() {
sandbox.stub(amplitude, 'logEvent');
sandbox.stub(window, 'ga');
sandbox.stub(window, 'fbq');
});
context('successful tracking', function() {
@@ -113,6 +106,15 @@ describe('Analytics Service', function () {
expect(ga).to.have.been.calledOnce;
expect(ga).to.have.been.calledWith('send', properties);
});
it('tracks a page view with Facebook', function() {
var properties = {'hitType':'pageview','eventCategory':'behavior','eventAction':'tasks'};
analytics.track(properties);
clock.tick();
expect(fbq).to.have.been.calledOnce;
expect(fbq).to.have.been.calledWith('track', 'PageView');
});
});
context('unsuccessful tracking', function() {
@@ -191,6 +193,8 @@ describe('Analytics Service', function () {
todos: 1,
rewards: 1
};
expectedProperties.balance = 12;
expectedProperties.balanceGemAmount = 48;
beforeEach(function() {
user._id = 'unique-user-id';
@@ -205,6 +209,7 @@ describe('Analytics Service', function () {
user.dailys = [{_id: 'daily'}];
user.todos = [{_id: 'todo'}];
user.rewards = [{_id: 'reward'}];
user.balance = 12;
analytics.updateUser(properties);
clock.tick();
@@ -238,7 +243,9 @@ describe('Analytics Service', function () {
dailys: 1,
habits: 1,
rewards: 1
}
},
balance: 12,
balanceGemAmount: 48
};
beforeEach(function() {
@@ -256,6 +263,7 @@ describe('Analytics Service', function () {
user.dailys = [{_id: 'daily'}];
user.todos = [{_id: 'todo'}];
user.rewards = [{_id: 'reward'}];
user.balance = 12;
analytics.updateUser();
clock.tick();