@tolinku/web-sdk 0.7.0 → 0.8.1

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.d.mts CHANGED
@@ -88,6 +88,19 @@ interface LeaderboardEntry {
88
88
  interface DeferredLink {
89
89
  deep_link_path: string;
90
90
  appspace_id: string;
91
+ /**
92
+ * The absolute URL for this link, built from your Appspace's own host.
93
+ *
94
+ * The same field the mobile SDKs carry, so a claim reads the same whichever
95
+ * one an app moves between. There it is what `trackLinkOpen` has to be given,
96
+ * since reporting an open needs the host and a device cannot know it. On the
97
+ * web there is nothing to report: a page load already reached us and was
98
+ * counted when it was served. It is here because the server sends it and a
99
+ * caller should not have to cast to see it.
100
+ *
101
+ * Absent from servers older than this field, so treat it as optional.
102
+ */
103
+ url?: string;
91
104
  referrer_id?: string;
92
105
  referral_code?: string;
93
106
  }
package/dist/index.d.ts CHANGED
@@ -88,6 +88,19 @@ interface LeaderboardEntry {
88
88
  interface DeferredLink {
89
89
  deep_link_path: string;
90
90
  appspace_id: string;
91
+ /**
92
+ * The absolute URL for this link, built from your Appspace's own host.
93
+ *
94
+ * The same field the mobile SDKs carry, so a claim reads the same whichever
95
+ * one an app moves between. There it is what `trackLinkOpen` has to be given,
96
+ * since reporting an open needs the host and a device cannot know it. On the
97
+ * web there is nothing to report: a page load already reached us and was
98
+ * counted when it was served. It is here because the server sends it and a
99
+ * caller should not have to cast to see it.
100
+ *
101
+ * Absent from servers older than this field, so treat it as optional.
102
+ */
103
+ url?: string;
91
104
  referrer_id?: string;
92
105
  referral_code?: string;
93
106
  }
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.7.0";
4
+ var SDK_VERSION = "0.8.1";
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);