Skip to content

Commit 96bc011

Browse files
feat: content filter callback
1 parent 0e23180 commit 96bc011

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
## X.X.X
1+
## XX.XX.XX
2+
3+
* Added a new init time config option for filtering contents:
4+
* `content_filter_callback`
5+
6+
## 25.4.2
27

38
* Mitigated an issue where manual feedback reporting could have failed
49
* Mitigated a possible issue with request timeouts in IE11

modules/CountlyClass.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class CountlyClass {
8888
#contentZoneTimer;
8989
#contentIframeID;
9090
#crashFilterCallback;
91+
#contentFilterCallback;
9192
#serverConfigCache;
9293
#SCNetwork;
9394
#SCSizeReqQueue;
@@ -169,6 +170,7 @@ class CountlyClass {
169170
this.#contentZoneTimer = null;
170171
this.#contentIframeID = "cly-content-iframe";
171172
this.#crashFilterCallback = null;
173+
this.#contentFilterCallback = null;
172174
this.#SCNetwork = true;
173175
this.#SCSizeReqQueue = getConfig("queue_size", ob, configurationDefaultValues.QUEUE_SIZE);
174176
this.#SCSizeEventBatch = getConfig("max_events", ob, configurationDefaultValues.MAX_EVENT_BATCH);
@@ -443,6 +445,7 @@ class CountlyClass {
443445
this.hcConsecutiveBackoffCount = this.#getValueFromStorage(healthCheckCounterEnum.consecutiveBackoffCount) || 0;
444446
this.#lastRequestWasBackoff = false; // Track if the previous request resulted in a backoff
445447
this.#crashFilterCallback = getConfig("crash_filter_callback", ob, null);
448+
this.#contentFilterCallback = getConfig("content_filter_callback", ob, null);
446449

447450
if (this.storage === "cookie") {
448451
this.#lsSupport = false;
@@ -4087,6 +4090,24 @@ class CountlyClass {
40874090
return;
40884091
}
40894092

4093+
// Build query params
4094+
const queryParams = { type: "content" };
4095+
4096+
const qIndex = response.html.indexOf("?");
4097+
if (qIndex !== -1) {
4098+
const search = response.html.slice(qIndex + 1);
4099+
new URLSearchParams(search).forEach((v, k) => {
4100+
queryParams[k] = v;
4101+
});
4102+
}
4103+
4104+
// Filter check
4105+
if (typeof this.#contentFilterCallback === "function" &&
4106+
this.#contentFilterCallback(queryParams) === false) {
4107+
this.#log(logLevelEnums.VERBOSE, "sendContentRequest, Content was filtered out by the content filter");
4108+
return;
4109+
}
4110+
40904111
this.#displayContent(response);
40914112
clearInterval(this.#contentZoneTimer); // prevent multiple content requests while one is on
40924113
window.addEventListener('message', (event) => {

0 commit comments

Comments
 (0)