Skip to content

Commit

Permalink
Override config (#460)
Browse files Browse the repository at this point in the history
* new one

* debug

* changelofg
  • Loading branch information
turtledreams committed Dec 15, 2023
1 parent 8b71e68 commit c991c6a
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 163 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 23.12.1
- Added methods for bridged SDK usage

## 23.12.0
- You can now provide custom storage methods to the SDK
- You can now use the SDK in web workers
Expand Down
45 changes: 45 additions & 0 deletions cypress/integration/bridge_utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint-disable cypress/no-unnecessary-waiting */
/* eslint-disable require-jsdoc */
var Countly = require("../../lib/countly");
// import * as Countly from "../../dist/countly_umd.js";
var hp = require("../support/helper.js");

function initMain(name, version) {
Countly.init({
app_key: "YOUR_APP_KEY",
url: "https://your.domain.count.ly",
test_mode: true,
debug: true,
sdk_name: name,
sdk_version: version
});
}

const SDK_NAME = "javascript_native_web";
const SDK_VERSION = "23.12.1";

// tests
describe("Bridged SDK Utilities Tests", () => {
it("Check if we can override sdk name and version successful", () => {
hp.haltAndClearStorage(() => {
initMain("javascript_gtm_web", "24.0.0");
hp.events();
cy.fetch_local_request_queue().then((eq) => {
expect(eq).to.have.length(1);
expect(eq[0].sdk_name).to.equal("javascript_gtm_web");
expect(eq[0].sdk_version).to.equal("24.0.0");
});
});
});
it("Check if SDK uses default values if SDK name and version was not overriden", () => {
hp.haltAndClearStorage(() => {
initMain(undefined, undefined);
hp.events();
cy.fetch_local_request_queue().then((eq) => {
expect(eq).to.have.length(1);
expect(eq[0].sdk_name).to.equal(SDK_NAME);
expect(eq[0].sdk_version).to.equal(SDK_VERSION);
});
});
});
});
23 changes: 15 additions & 8 deletions lib/countly.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
statusCode: "cly_hc_status_code",
errorMessage: "cly_hc_error_message"
});
var SDK_VERSION = "23.12.0";
var SDK_VERSION = "23.12.1";
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 Expand Up @@ -807,6 +807,8 @@
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.
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.
var freshUTMTags = null;
var sdkName = getConfig("sdk_name", ob, SDK_NAME);
var sdkVersion = getConfig("sdk_version", ob, SDK_VERSION);
try {
localStorage.setItem("cly_testLocal", true);
// clean up test
Expand Down Expand Up @@ -970,6 +972,11 @@

// init configuration is printed out here:
// key values should be printed out as is
if (sdkName === SDK_NAME && sdkVersion === SDK_VERSION) {
log(logLevelEnums.DEBUG, "initialize, SDK name:[" + sdkName + "], version:[" + sdkVersion + "]");
} else {
log(logLevelEnums.DEBUG, "initialize, SDK name:[" + sdkName + "], version:[" + sdkVersion + "], default name:[" + SDK_NAME + "] and default version:[" + SDK_VERSION + "]");
}
log(logLevelEnums.DEBUG, "initialize, app_key:[" + this.app_key + "], url:[" + this.url + "]");
log(logLevelEnums.DEBUG, "initialize, device_id:[" + getConfig("device_id", ob, undefined) + "]");
log(logLevelEnums.DEBUG, "initialize, require_consent is enabled:[" + this.require_consent + "]");
Expand Down Expand Up @@ -3540,8 +3547,8 @@
var data = {
widget_id: CountlyFeedbackWidget._id,
shown: 1,
sdk_version: SDK_VERSION,
sdk_name: SDK_NAME,
sdk_version: sdkVersion,
sdk_name: sdkName,
platform: this.platform,
app_version: this.app_version
};
Expand Down Expand Up @@ -3646,10 +3653,10 @@
url += "?widget_id=" + presentableFeedback._id;
url += "&app_key=" + this.app_key;
url += "&device_id=" + this.device_id;
url += "&sdk_name=" + SDK_NAME;
url += "&sdk_name=" + sdkName;
url += "&platform=" + this.platform;
url += "&app_version=" + this.app_version;
url += "&sdk_version=" + SDK_VERSION;
url += "&sdk_version=" + sdkVersion;
if (feedbackWidgetSegmentation) {
var customObjectToSendWithTheWidget = {};
customObjectToSendWithTheWidget.sg = feedbackWidgetSegmentation;
Expand Down Expand Up @@ -4049,7 +4056,7 @@
var iframe = document.createElement("iframe");
iframe.name = "countly-feedback-iframe";
iframe.id = "countly-feedback-iframe";
iframe.src = self.url + "/feedback?widget_id=" + currentWidget._id + "&app_key=" + self.app_key + "&device_id=" + self.device_id + "&sdk_version=" + SDK_VERSION;
iframe.src = self.url + "/feedback?widget_id=" + currentWidget._id + "&app_key=" + self.app_key + "&device_id=" + self.device_id + "&sdk_version=" + sdkVersion;
// inject them to dom
document.body.appendChild(wrapper);
wrapper.appendChild(closeIcon);
Expand Down Expand Up @@ -4173,8 +4180,8 @@
function prepareRequest(request) {
request.app_key = self.app_key;
request.device_id = self.device_id;
request.sdk_name = SDK_NAME;
request.sdk_version = SDK_VERSION;
request.sdk_name = sdkName;
request.sdk_version = sdkVersion;
request.t = deviceIdType;
request.av = self.app_version;
var ua = getUA();
Expand Down
Loading

0 comments on commit c991c6a

Please sign in to comment.