@tolinku/web-sdk 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +33 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -1
- package/dist/index.mjs.map +1 -1
- package/dist/tolinku.min.js +11 -11
- package/dist/tolinku.min.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/types.ts
|
|
4
|
-
var SDK_VERSION = "0.
|
|
4
|
+
var SDK_VERSION = "0.8.0";
|
|
5
5
|
|
|
6
6
|
// src/client.ts
|
|
7
7
|
var MAX_RETRIES = 3;
|
|
@@ -862,6 +862,35 @@ var Banners = class {
|
|
|
862
862
|
this.currentStyle = "pinned";
|
|
863
863
|
this.currentPosition = "top";
|
|
864
864
|
}
|
|
865
|
+
/**
|
|
866
|
+
* Tell the server a banner was tapped.
|
|
867
|
+
*
|
|
868
|
+
* sendBeacon, because the navigation that follows cancels a plain fetch. It
|
|
869
|
+
* is queued by the browser and delivered regardless, which is the only way to
|
|
870
|
+
* report something that happens as the page is being left.
|
|
871
|
+
*
|
|
872
|
+
* Never throws and never awaits: a banner that cannot report a tap must still
|
|
873
|
+
* open the link.
|
|
874
|
+
*/
|
|
875
|
+
reportClick(bannerId, target) {
|
|
876
|
+
try {
|
|
877
|
+
const url = this.client.baseUrl + "/v1/api/banner/click";
|
|
878
|
+
const body = JSON.stringify({ banner_id: bannerId, target });
|
|
879
|
+
const nav = navigator;
|
|
880
|
+
if (typeof nav.sendBeacon === "function") {
|
|
881
|
+
nav.sendBeacon(url, new Blob([body], { type: "application/json" }));
|
|
882
|
+
} else {
|
|
883
|
+
void fetch(url, {
|
|
884
|
+
method: "POST",
|
|
885
|
+
headers: { "Content-Type": "application/json" },
|
|
886
|
+
body,
|
|
887
|
+
keepalive: true
|
|
888
|
+
}).catch(() => {
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
} catch {
|
|
892
|
+
}
|
|
893
|
+
}
|
|
865
894
|
/** Fetch banner config and show the highest-priority banner */
|
|
866
895
|
async show(options = {}, userId) {
|
|
867
896
|
const params = {};
|
|
@@ -1095,6 +1124,9 @@ var Banners = class {
|
|
|
1095
1124
|
cta.className = "tolk-cta";
|
|
1096
1125
|
cta.href = isSafeUrl(installUrl) ? installUrl : "#";
|
|
1097
1126
|
cta.textContent = ctaText;
|
|
1127
|
+
cta.addEventListener("click", () => {
|
|
1128
|
+
this.reportClick(banner.id, cta.href);
|
|
1129
|
+
});
|
|
1098
1130
|
inner.appendChild(cta);
|
|
1099
1131
|
container.appendChild(inner);
|
|
1100
1132
|
document.head.appendChild(style);
|