0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

🐛 Fixed source tracking using cached value (#15778)

refs https://ghost.slack.com/archives/C02G9E68C/p1667834794676479

- When enabling tracking, it could be the case that the server is ignoring the attributions because of the cached setting value.
- When disabling tracking, the frontend should take care of not
collecting new tracking information to the server, but still the backend value should be used as a fail-safe.
This commit is contained in:
Simon Backx 2022-11-07 16:55:17 +01:00 committed by GitHub
parent 3048c7e790
commit 2a2f5cca50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 12 deletions

View file

@ -40,7 +40,7 @@ class MemberAttributionServiceWrapper {
Integration: models.Integration Integration: models.Integration
}, },
attributionBuilder: this.attributionBuilder, attributionBuilder: this.attributionBuilder,
isTrackingEnabled: !!settingsCache.get('members_track_sources') getTrackingEnabled: () => !!settingsCache.get('members_track_sources')
}); });
} }
} }

View file

@ -5,15 +5,19 @@ class MemberAttributionService {
* *
* @param {Object} deps * @param {Object} deps
* @param {Object} deps.attributionBuilder * @param {Object} deps.attributionBuilder
* @param {boolean} deps.isTrackingEnabled
* @param {Object} deps.models * @param {Object} deps.models
* @param {Object} deps.models.MemberCreatedEvent * @param {Object} deps.models.MemberCreatedEvent
* @param {Object} deps.models.SubscriptionCreatedEvent * @param {Object} deps.models.SubscriptionCreatedEvent
* @param {() => boolean} deps.getTrackingEnabled
*/ */
constructor({attributionBuilder, models, isTrackingEnabled}) { constructor({attributionBuilder, models, getTrackingEnabled}) {
this.models = models; this.models = models;
this.attributionBuilder = attributionBuilder; this.attributionBuilder = attributionBuilder;
this.isTrackingEnabled = isTrackingEnabled; this._getTrackingEnabled = getTrackingEnabled;
}
get isTrackingEnabled() {
return this._getTrackingEnabled();
} }
/** /**

View file

@ -13,7 +13,7 @@ describe('MemberAttributionService', function () {
describe('getAttributionFromContext', function () { describe('getAttributionFromContext', function () {
it('returns null if no context is provided', async function () { it('returns null if no context is provided', async function () {
const service = new MemberAttributionService({ const service = new MemberAttributionService({
isTrackingEnabled: true getTrackingEnabled: () => true
}); });
const attribution = await service.getAttributionFromContext(); const attribution = await service.getAttributionFromContext();
@ -31,7 +31,7 @@ describe('MemberAttributionService', function () {
it('returns attribution for importer context', async function () { it('returns attribution for importer context', async function () {
const service = new MemberAttributionService({ const service = new MemberAttributionService({
isTrackingEnabled: true getTrackingEnabled: () => true
}); });
const attribution = await service.getAttributionFromContext({importer: true}); const attribution = await service.getAttributionFromContext({importer: true});
@ -40,7 +40,7 @@ describe('MemberAttributionService', function () {
it('returns attribution for admin context', async function () { it('returns attribution for admin context', async function () {
const service = new MemberAttributionService({ const service = new MemberAttributionService({
isTrackingEnabled: true getTrackingEnabled: () => true
}); });
const attribution = await service.getAttributionFromContext({user: 'abc'}); const attribution = await service.getAttributionFromContext({user: 'abc'});
@ -49,7 +49,7 @@ describe('MemberAttributionService', function () {
it('returns attribution for api without integration context', async function () { it('returns attribution for api without integration context', async function () {
const service = new MemberAttributionService({ const service = new MemberAttributionService({
isTrackingEnabled: true getTrackingEnabled: () => true
}); });
const attribution = await service.getAttributionFromContext({ const attribution = await service.getAttributionFromContext({
api_key: 'abc' api_key: 'abc'
@ -69,7 +69,7 @@ describe('MemberAttributionService', function () {
} }
} }
}, },
isTrackingEnabled: true getTrackingEnabled: () => true
}); });
const attribution = await service.getAttributionFromContext({ const attribution = await service.getAttributionFromContext({
api_key: 'abc', api_key: 'abc',
@ -96,7 +96,7 @@ describe('MemberAttributionService', function () {
}; };
} }
}, },
isTrackingEnabled: true getTrackingEnabled: () => true
}); });
const model = { const model = {
id: 'event_id', id: 'event_id',
@ -130,7 +130,7 @@ describe('MemberAttributionService', function () {
}; };
} }
}, },
isTrackingEnabled: true getTrackingEnabled: () => true
}); });
const model = { const model = {
id: 'event_id', id: 'event_id',
@ -170,7 +170,7 @@ describe('MemberAttributionService', function () {
}; };
} }
}, },
isTrackingEnabled: true getTrackingEnabled: () => true
}); });
const model = { const model = {
id: 'event_id', id: 'event_id',