0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Added config flag to disable link click tracking (#21853)

no ref

This isn't needed at this time. We're doing some load testing to better
assess what piece is doing the most work, and this config flag lets us
shut off pieces of the redirect flow.
This commit is contained in:
Steve Larson 2024-12-10 10:08:58 -06:00 committed by GitHub
parent 04f0b9fc3f
commit 109c7b70ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 26 additions and 2 deletions

View file

@ -2,6 +2,7 @@ const LinkClickRepository = require('./LinkClickRepository');
const PostLinkRepository = require('./PostLinkRepository');
const errors = require('@tryghost/errors');
const urlUtils = require('../../../shared/url-utils');
const config = require('../../../shared/config');
class LinkTrackingServiceWrapper {
async init() {
@ -40,7 +41,8 @@ class LinkTrackingServiceWrapper {
linkClickRepository: this.linkClickRepository,
postLinkRepository,
DomainEvents,
urlUtils
urlUtils,
config
});
await this.service.init();

View file

@ -192,6 +192,7 @@
"stripeDirect": false,
"enableStripePromoCodes": false,
"emailAnalytics": true,
"linkClickTracking": true,
"backgroundJobs": {
"emailAnalytics": true,
"clickTrackingLastSeenAtUpdater": true

View file

@ -61,6 +61,8 @@ class LinkClickTrackingService {
#LinkRedirect;
/** @type {Object} */
#urlUtils;
/** @type {Object} */
#config;
/**
* @param {object} deps
@ -69,6 +71,7 @@ class LinkClickTrackingService {
* @param {IPostLinkRepository} deps.postLinkRepository
* @param {DomainEvents} deps.DomainEvents
* @param {urlUtils} deps.urlUtils
* @param {config} deps.config
*/
constructor(deps) {
this.#linkClickRepository = deps.linkClickRepository;
@ -76,13 +79,17 @@ class LinkClickTrackingService {
this.#postLinkRepository = deps.postLinkRepository;
this.#DomainEvents = deps.DomainEvents;
this.#urlUtils = deps.urlUtils;
this.#config = deps.config;
}
async init() {
if (this.#initialised) {
return;
}
if (!this.#config || this.#config.get('linkClickTracking')) {
this.subscribe();
}
this.#initialised = true;
}

View file

@ -13,6 +13,10 @@ describe('LinkClickTrackingService', function () {
});
describe('init', function () {
afterEach(function () {
sinon.restore();
});
it('initialises only once', function () {
const subscribe = sinon.stub();
const service = new LinkClickTrackingService({
@ -25,6 +29,16 @@ describe('LinkClickTrackingService', function () {
service.init();
assert.ok(subscribe.calledOnce);
});
it('does not subscribe if linkClickTracking is false', function () {
const subscribe = sinon.stub();
const service = new LinkClickTrackingService({
config: {get: sinon.stub().returns(false)},
DomainEvents: {subscribe}
});
service.init();
assert.ok(!subscribe.called);
});
});
describe('getLinks', function () {