Skip to content

Commit

Permalink
Merge pull request #4 from Countly/bot-detections
Browse files Browse the repository at this point in the history
Worker improvements
  • Loading branch information
ArtursKadikis authored Dec 28, 2023
2 parents adcc964 + 69c7fad commit 2330819
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 23.12.3

* Added bot detection for workers
* Added the ability to clear stored device IDs in the workers

## 23.12.2

* Added Google Lighthouse to bot detection
Expand Down
2 changes: 2 additions & 0 deletions cypress/e2e/user_agent.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ describe("User Agent tests ", () => {
expect(Countly._internals.userAgentSearchBotDetection("123")).to.equal(false);
expect(Countly._internals.userAgentSearchBotDetection("Googlebot")).to.equal(true);
expect(Countly._internals.userAgentSearchBotDetection("Google")).to.equal(false);
expect(Countly._internals.userAgentSearchBotDetection("HeadlessChrome")).to.equal(true);
expect(Countly._internals.userAgentSearchBotDetection("Chrome-Lighthouse")).to.equal(true);
});
});
});
2 changes: 1 addition & 1 deletion examples/example_web_worker.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<body>
<!-- Header, banner etc. Top part of your site -->
<div id="header">
<h1>Sync Countly Implementation</h1>
<h1>Worker Countly Implementation</h1>
<img id="logo" src="./images/logo.png">
</div>

Expand Down
1 change: 1 addition & 0 deletions examples/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://your.domain.count.ly",
debug: true,
clear_stored_id: true, // Resets the stored device ID on init
storage: {
getItem: (key) => {
return STORAGE[key];
Expand Down
2 changes: 1 addition & 1 deletion modules/Constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var healthCheckCounterEnum = Object.freeze({
errorMessage: "cly_hc_error_message",
});

var SDK_VERSION = "23.12.2";
var SDK_VERSION = "23.12.3";
var SDK_NAME = "javascript_native_web";

// Using this on document.referrer would return an array with 15 elements in it. The 12th element (array[11]) would be the path we are looking for. Others would be things like password and such (use https://regex101.com/ to check more)
Expand Down
13 changes: 8 additions & 5 deletions modules/CountlyClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class CountlyClass {
this.getSearchQuery = getConfig("getSearchQuery", ob, Countly.getSearchQuery);
this.DeviceIdType = Countly.DeviceIdType; // it is Countly device Id type Enums for clients to use
this.namespace = getConfig("namespace", ob, "");
this.clearStoredId = !isBrowser ? undefined : getConfig("clear_stored_id", ob, false);
this.clearStoredId = getConfig("clear_stored_id", ob, false);
this.app_key = getConfig("app_key", ob, null);
this.onload = getConfig("onload", ob, []);
this.utm = getConfig("utm", ob, { source: true, medium: true, campaign: true, term: true, content: true });
Expand All @@ -124,7 +124,7 @@ class CountlyClass {
this.country_code = getConfig("country_code", ob, null);
this.city = getConfig("city", ob, null);
this.ip_address = getConfig("ip_address", ob, null);
this.ignore_bots = !isBrowser ? undefined : getConfig("ignore_bots", ob, true);
this.ignore_bots = getConfig("ignore_bots", ob, true);
this.force_post = getConfig("force_post", ob, false);
this.remote_config = getConfig("remote_config", ob, false);
this.ignore_visitor = getConfig("ignore_visitor", ob, false);
Expand Down Expand Up @@ -197,9 +197,9 @@ class CountlyClass {
}
// then clear the storage so that a new device ID is set again later
log(logLevelEnums.INFO, "initialize, Clearing the device ID storage");
localStorage.removeItem(this.app_key + "/cly_id");
localStorage.removeItem(this.app_key + "/cly_id_type");
localStorage.removeItem(this.app_key + "/cly_session");
removeValueFromStorage("cly_id");
removeValueFromStorage("cly_id_type");
removeValueFromStorage("cly_session");
}

checkIgnore();
Expand Down Expand Up @@ -3425,11 +3425,14 @@ class CountlyClass {
* Check if user or visit should be ignored
*/
function checkIgnore() {
log(logLevelEnums.INFO, "checkIgnore, Checking if user or visit should be ignored");
if (self.ignore_prefetch && isBrowser && typeof document.visibilityState !== "undefined" && document.visibilityState === "prerender") {
self.ignore_visitor = true;
log(logLevelEnums.DEBUG, "checkIgnore, Ignoring visit due to prerendering");
}
if (self.ignore_bots && userAgentSearchBotDetection()) {
self.ignore_visitor = true;
log(logLevelEnums.DEBUG, "checkIgnore, Ignoring visit due to bot");
}
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "countly-sdk-js",
"version": "23.12.2",
"version": "23.12.3",
"description": "Countly JavaScript SDK",
"type": "module",
"main": "Countly.js",
Expand Down

0 comments on commit 2330819

Please sign in to comment.