Skip to content

Commit c991c6a

Browse files
authored
Override config (#460)
* new one * debug * changelofg
1 parent 8b71e68 commit c991c6a

File tree

5 files changed

+218
-163
lines changed

5 files changed

+218
-163
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 23.12.1
2+
- Added methods for bridged SDK usage
3+
14
## 23.12.0
25
- You can now provide custom storage methods to the SDK
36
- You can now use the SDK in web workers

cypress/integration/bridge_utils.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/* eslint-disable cypress/no-unnecessary-waiting */
2+
/* eslint-disable require-jsdoc */
3+
var Countly = require("../../lib/countly");
4+
// import * as Countly from "../../dist/countly_umd.js";
5+
var hp = require("../support/helper.js");
6+
7+
function initMain(name, version) {
8+
Countly.init({
9+
app_key: "YOUR_APP_KEY",
10+
url: "https://your.domain.count.ly",
11+
test_mode: true,
12+
debug: true,
13+
sdk_name: name,
14+
sdk_version: version
15+
});
16+
}
17+
18+
const SDK_NAME = "javascript_native_web";
19+
const SDK_VERSION = "23.12.1";
20+
21+
// tests
22+
describe("Bridged SDK Utilities Tests", () => {
23+
it("Check if we can override sdk name and version successful", () => {
24+
hp.haltAndClearStorage(() => {
25+
initMain("javascript_gtm_web", "24.0.0");
26+
hp.events();
27+
cy.fetch_local_request_queue().then((eq) => {
28+
expect(eq).to.have.length(1);
29+
expect(eq[0].sdk_name).to.equal("javascript_gtm_web");
30+
expect(eq[0].sdk_version).to.equal("24.0.0");
31+
});
32+
});
33+
});
34+
it("Check if SDK uses default values if SDK name and version was not overriden", () => {
35+
hp.haltAndClearStorage(() => {
36+
initMain(undefined, undefined);
37+
hp.events();
38+
cy.fetch_local_request_queue().then((eq) => {
39+
expect(eq).to.have.length(1);
40+
expect(eq[0].sdk_name).to.equal(SDK_NAME);
41+
expect(eq[0].sdk_version).to.equal(SDK_VERSION);
42+
});
43+
});
44+
});
45+
});

lib/countly.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
statusCode: "cly_hc_status_code",
197197
errorMessage: "cly_hc_error_message"
198198
});
199-
var SDK_VERSION = "23.12.0";
199+
var SDK_VERSION = "23.12.1";
200200
var SDK_NAME = "javascript_native_web";
201201

202202
// 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)
@@ -807,6 +807,8 @@
807807
var currentViewId = null; // this is the global variable for tracking the current view's ID. Used in view tracking. Becomes previous view ID at the end.
808808
var previousViewId = null; // this is the global variable for tracking the previous view's ID. Used in view tracking. First view has no previous view ID.
809809
var freshUTMTags = null;
810+
var sdkName = getConfig("sdk_name", ob, SDK_NAME);
811+
var sdkVersion = getConfig("sdk_version", ob, SDK_VERSION);
810812
try {
811813
localStorage.setItem("cly_testLocal", true);
812814
// clean up test
@@ -970,6 +972,11 @@
970972

971973
// init configuration is printed out here:
972974
// key values should be printed out as is
975+
if (sdkName === SDK_NAME && sdkVersion === SDK_VERSION) {
976+
log(logLevelEnums.DEBUG, "initialize, SDK name:[" + sdkName + "], version:[" + sdkVersion + "]");
977+
} else {
978+
log(logLevelEnums.DEBUG, "initialize, SDK name:[" + sdkName + "], version:[" + sdkVersion + "], default name:[" + SDK_NAME + "] and default version:[" + SDK_VERSION + "]");
979+
}
973980
log(logLevelEnums.DEBUG, "initialize, app_key:[" + this.app_key + "], url:[" + this.url + "]");
974981
log(logLevelEnums.DEBUG, "initialize, device_id:[" + getConfig("device_id", ob, undefined) + "]");
975982
log(logLevelEnums.DEBUG, "initialize, require_consent is enabled:[" + this.require_consent + "]");
@@ -3540,8 +3547,8 @@
35403547
var data = {
35413548
widget_id: CountlyFeedbackWidget._id,
35423549
shown: 1,
3543-
sdk_version: SDK_VERSION,
3544-
sdk_name: SDK_NAME,
3550+
sdk_version: sdkVersion,
3551+
sdk_name: sdkName,
35453552
platform: this.platform,
35463553
app_version: this.app_version
35473554
};
@@ -3646,10 +3653,10 @@
36463653
url += "?widget_id=" + presentableFeedback._id;
36473654
url += "&app_key=" + this.app_key;
36483655
url += "&device_id=" + this.device_id;
3649-
url += "&sdk_name=" + SDK_NAME;
3656+
url += "&sdk_name=" + sdkName;
36503657
url += "&platform=" + this.platform;
36513658
url += "&app_version=" + this.app_version;
3652-
url += "&sdk_version=" + SDK_VERSION;
3659+
url += "&sdk_version=" + sdkVersion;
36533660
if (feedbackWidgetSegmentation) {
36543661
var customObjectToSendWithTheWidget = {};
36553662
customObjectToSendWithTheWidget.sg = feedbackWidgetSegmentation;
@@ -4049,7 +4056,7 @@
40494056
var iframe = document.createElement("iframe");
40504057
iframe.name = "countly-feedback-iframe";
40514058
iframe.id = "countly-feedback-iframe";
4052-
iframe.src = self.url + "/feedback?widget_id=" + currentWidget._id + "&app_key=" + self.app_key + "&device_id=" + self.device_id + "&sdk_version=" + SDK_VERSION;
4059+
iframe.src = self.url + "/feedback?widget_id=" + currentWidget._id + "&app_key=" + self.app_key + "&device_id=" + self.device_id + "&sdk_version=" + sdkVersion;
40534060
// inject them to dom
40544061
document.body.appendChild(wrapper);
40554062
wrapper.appendChild(closeIcon);
@@ -4173,8 +4180,8 @@
41734180
function prepareRequest(request) {
41744181
request.app_key = self.app_key;
41754182
request.device_id = self.device_id;
4176-
request.sdk_name = SDK_NAME;
4177-
request.sdk_version = SDK_VERSION;
4183+
request.sdk_name = sdkName;
4184+
request.sdk_version = sdkVersion;
41784185
request.t = deviceIdType;
41794186
request.av = self.app_version;
41804187
var ua = getUA();

0 commit comments

Comments
 (0)