mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
Track unsubscription
This commit is contained in:
@@ -167,73 +167,78 @@ describe('analytics', function() {
|
|||||||
analytics.__set__('ga.transaction', googleTransaction);
|
analytics.__set__('ga.transaction', googleTransaction);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls amplitude.track', function() {
|
context('Amplitude', function() {
|
||||||
|
|
||||||
initializedAnalytics.trackPurchase(purchaseData);
|
it('calls amplitude.track', function() {
|
||||||
|
var data = _.cloneDeep(purchaseData);
|
||||||
|
initializedAnalytics.trackPurchase(data);
|
||||||
|
|
||||||
expect(amplitudeTrack).to.be.calledOnce;
|
expect(amplitudeTrack).to.be.calledOnce;
|
||||||
expect(amplitudeTrack).to.be.calledWith({
|
expect(amplitudeTrack).to.be.calledWith({
|
||||||
event_type: 'purchase',
|
event_type: 'purchase',
|
||||||
user_id: 'user-id',
|
user_id: 'user-id',
|
||||||
event_properties: {
|
event_properties: {
|
||||||
paymentMethod: 'PayPal',
|
paymentMethod: 'PayPal',
|
||||||
sku: 'paypal-checkout',
|
sku: 'paypal-checkout',
|
||||||
gift: false,
|
gift: false,
|
||||||
itemPurchased: 'Gems',
|
itemPurchased: 'Gems',
|
||||||
purchaseType: 'checkout',
|
purchaseType: 'checkout',
|
||||||
quantity: 1
|
quantity: 1
|
||||||
},
|
},
|
||||||
revenue: 8
|
revenue: 8
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls ga.event', function() {
|
context('Google Analytics', function() {
|
||||||
|
|
||||||
initializedAnalytics.trackPurchase(purchaseData);
|
it('calls ga.event', function() {
|
||||||
|
var data = _.cloneDeep(purchaseData);
|
||||||
|
initializedAnalytics.trackPurchase(data);
|
||||||
|
|
||||||
expect(googleEvent).to.be.calledOnce;
|
expect(googleEvent).to.be.calledOnce;
|
||||||
expect(googleEvent).to.be.calledWith(
|
expect(googleEvent).to.be.calledWith(
|
||||||
'commerce',
|
'commerce',
|
||||||
'checkout',
|
'checkout',
|
||||||
'PayPal',
|
'PayPal',
|
||||||
8
|
8
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls ga.transaction', function() {
|
it('calls ga.transaction', function() {
|
||||||
|
var data = _.cloneDeep(purchaseData);
|
||||||
|
initializedAnalytics.trackPurchase(data);
|
||||||
|
|
||||||
initializedAnalytics.trackPurchase(purchaseData);
|
expect(googleTransaction).to.be.calledOnce;
|
||||||
|
expect(googleTransaction).to.be.calledWith(
|
||||||
|
'user-id',
|
||||||
|
8
|
||||||
|
);
|
||||||
|
expect(googleItem).to.be.calledOnce;
|
||||||
|
expect(googleItem).to.be.calledWith(
|
||||||
|
8,
|
||||||
|
1,
|
||||||
|
'paypal-checkout',
|
||||||
|
'Gems',
|
||||||
|
'checkout'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
expect(googleTransaction).to.be.calledOnce;
|
it('appends gift to variation of ga.transaction.item if gift is true', function() {
|
||||||
expect(googleTransaction).to.be.calledWith(
|
|
||||||
'user-id',
|
|
||||||
8
|
|
||||||
);
|
|
||||||
expect(googleItem).to.be.calledOnce;
|
|
||||||
expect(googleItem).to.be.calledWith(
|
|
||||||
8,
|
|
||||||
1,
|
|
||||||
'paypal-checkout',
|
|
||||||
'Gems',
|
|
||||||
'checkout'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('appends gift to variation of ga.transaction.item if gift is true', function() {
|
var data = _.cloneDeep(purchaseData);
|
||||||
|
data.gift = true;
|
||||||
|
initializedAnalytics.trackPurchase(data);
|
||||||
|
|
||||||
var purchaseDataWithGift = _.clone(purchaseData);
|
expect(googleItem).to.be.calledOnce;
|
||||||
purchaseDataWithGift.gift = true;
|
expect(googleItem).to.be.calledWith(
|
||||||
|
8,
|
||||||
initializedAnalytics.trackPurchase(purchaseDataWithGift);
|
1,
|
||||||
|
'paypal-checkout',
|
||||||
expect(googleItem).to.be.calledOnce;
|
'Gems',
|
||||||
expect(googleItem).to.be.calledWith(
|
'checkout - Gift'
|
||||||
8,
|
);
|
||||||
1,
|
});
|
||||||
'paypal-checkout',
|
|
||||||
'Gems',
|
|
||||||
'checkout - Gift'
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -127,7 +127,13 @@ exports.cancelSubscription = function(data, cb) {
|
|||||||
|
|
||||||
data.user.save(cb);
|
data.user.save(cb);
|
||||||
utils.txnEmail(data.user, 'cancel-subscription');
|
utils.txnEmail(data.user, 'cancel-subscription');
|
||||||
utils.ga.event('commerce', 'unsubscribe', data.paymentMethod).send();
|
var analyticsData = {
|
||||||
|
uuid: data.user._id,
|
||||||
|
gaCategory: 'commerce',
|
||||||
|
gaLabel: data.paymentMethod,
|
||||||
|
paymentMethod: data.paymentMethod
|
||||||
|
}
|
||||||
|
utils.analytics.track('unsubscribe', analyticsData);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.buyGems = function(data, cb) {
|
exports.buyGems = function(data, cb) {
|
||||||
|
|||||||
Reference in New Issue
Block a user