@tolinku/web-sdk 0.6.1 → 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.d.mts CHANGED
@@ -569,4 +569,5 @@ declare class Tolinku {
569
569
  destroy(): void;
570
570
  }
571
571
 
572
- export { type AddPaymentInfoParams, type AddToCartParams, type AddToWishlistParams, type BannerConfig, type BannerItem, type BeginCheckoutParams, type ClaimBySignalsOptions, type CompleteReferralOptions, type CompleteReferralResult, type CreateReferralOptions, type CreateReferralResult, type DeferredLink, type EcommerceItem, type LeaderboardEntry, type Message, type MessageAppContext, type MessageComponent, type MessageContent, type MilestoneOptions, type MilestoneResult, type PurchaseParams, type RateParams, type ReferralInfo, type RefundParams, type RemoveFromCartParams, type ResolvedLink, type SearchParams, type ShareParams, type ShowBannerOptions, type ShowMessageOptions, type SpendCreditsParams, Tolinku, type TolinkuConfig, TolinkuError, type TrackProperties, type ViewItemParams };
572
+ export { Tolinku, TolinkuError };
573
+ export type { AddPaymentInfoParams, AddToCartParams, AddToWishlistParams, BannerConfig, BannerItem, BeginCheckoutParams, ClaimBySignalsOptions, CompleteReferralOptions, CompleteReferralResult, CreateReferralOptions, CreateReferralResult, DeferredLink, EcommerceItem, LeaderboardEntry, Message, MessageAppContext, MessageComponent, MessageContent, MilestoneOptions, MilestoneResult, PurchaseParams, RateParams, ReferralInfo, RefundParams, RemoveFromCartParams, ResolvedLink, SearchParams, ShareParams, ShowBannerOptions, ShowMessageOptions, SpendCreditsParams, TolinkuConfig, TrackProperties, ViewItemParams };
package/dist/index.d.ts CHANGED
@@ -569,4 +569,5 @@ declare class Tolinku {
569
569
  destroy(): void;
570
570
  }
571
571
 
572
- export { type AddPaymentInfoParams, type AddToCartParams, type AddToWishlistParams, type BannerConfig, type BannerItem, type BeginCheckoutParams, type ClaimBySignalsOptions, type CompleteReferralOptions, type CompleteReferralResult, type CreateReferralOptions, type CreateReferralResult, type DeferredLink, type EcommerceItem, type LeaderboardEntry, type Message, type MessageAppContext, type MessageComponent, type MessageContent, type MilestoneOptions, type MilestoneResult, type PurchaseParams, type RateParams, type ReferralInfo, type RefundParams, type RemoveFromCartParams, type ResolvedLink, type SearchParams, type ShareParams, type ShowBannerOptions, type ShowMessageOptions, type SpendCreditsParams, Tolinku, type TolinkuConfig, TolinkuError, type TrackProperties, type ViewItemParams };
572
+ export { Tolinku, TolinkuError };
573
+ export type { AddPaymentInfoParams, AddToCartParams, AddToWishlistParams, BannerConfig, BannerItem, BeginCheckoutParams, ClaimBySignalsOptions, CompleteReferralOptions, CompleteReferralResult, CreateReferralOptions, CreateReferralResult, DeferredLink, EcommerceItem, LeaderboardEntry, Message, MessageAppContext, MessageComponent, MessageContent, MilestoneOptions, MilestoneResult, PurchaseParams, RateParams, ReferralInfo, RefundParams, RemoveFromCartParams, ResolvedLink, SearchParams, ShareParams, ShowBannerOptions, ShowMessageOptions, SpendCreditsParams, TolinkuConfig, TrackProperties, ViewItemParams };
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.6.1";
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);