@scalemule/nextjs 0.0.27 → 0.0.28

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 CHANGED
@@ -2726,14 +2726,22 @@ function useAnalytics(options = {}) {
2726
2726
  const sendEvent = react.useCallback(
2727
2727
  async (event) => {
2728
2728
  const fullEvent = buildFullEvent(event);
2729
+ const payload = JSON.stringify(fullEvent);
2729
2730
  if (analyticsProxyUrl) {
2730
- fetch(analyticsProxyUrl, {
2731
- method: "POST",
2732
- headers: { "Content-Type": "application/json" },
2733
- body: JSON.stringify(fullEvent)
2734
- }).catch((err) => {
2735
- console.debug("[ScaleMule Analytics] Proxy tracking failed:", err);
2736
- });
2731
+ const sent = typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function" && navigator.sendBeacon(
2732
+ analyticsProxyUrl,
2733
+ new Blob([payload], { type: "application/json" })
2734
+ );
2735
+ if (!sent) {
2736
+ fetch(analyticsProxyUrl, {
2737
+ method: "POST",
2738
+ headers: { "Content-Type": "application/json" },
2739
+ body: payload,
2740
+ keepalive: true
2741
+ }).catch((err) => {
2742
+ console.debug("[ScaleMule Analytics] Proxy tracking failed:", err);
2743
+ });
2744
+ }
2737
2745
  return { tracked: 1, session_id: sessionIdRef.current || void 0 };
2738
2746
  }
2739
2747
  if (publishableKey && gatewayUrl) {
@@ -2744,7 +2752,8 @@ function useAnalytics(options = {}) {
2744
2752
  "Content-Type": "application/json",
2745
2753
  "x-api-key": publishableKey
2746
2754
  },
2747
- body: JSON.stringify(fullEvent)
2755
+ body: payload,
2756
+ keepalive: true
2748
2757
  }).catch((err) => {
2749
2758
  console.debug("[ScaleMule Analytics] Direct tracking failed:", err);
2750
2759
  });
@@ -2807,13 +2816,21 @@ function useAnalytics(options = {}) {
2807
2816
  const fullEvents = events.map((event) => buildFullEvent(event));
2808
2817
  if (analyticsProxyUrl) {
2809
2818
  for (const event of fullEvents) {
2810
- fetch(analyticsProxyUrl, {
2811
- method: "POST",
2812
- headers: { "Content-Type": "application/json" },
2813
- body: JSON.stringify(event)
2814
- }).catch((err) => {
2815
- console.debug("[ScaleMule Analytics] Proxy batch tracking failed:", err);
2816
- });
2819
+ const payload = JSON.stringify(event);
2820
+ const sent = typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function" && navigator.sendBeacon(
2821
+ analyticsProxyUrl,
2822
+ new Blob([payload], { type: "application/json" })
2823
+ );
2824
+ if (!sent) {
2825
+ fetch(analyticsProxyUrl, {
2826
+ method: "POST",
2827
+ headers: { "Content-Type": "application/json" },
2828
+ body: payload,
2829
+ keepalive: true
2830
+ }).catch((err) => {
2831
+ console.debug("[ScaleMule Analytics] Proxy batch tracking failed:", err);
2832
+ });
2833
+ }
2817
2834
  }
2818
2835
  setLoading(false);
2819
2836
  return { tracked: events.length, session_id: sessionIdRef.current || void 0 };
@@ -2826,7 +2843,8 @@ function useAnalytics(options = {}) {
2826
2843
  "Content-Type": "application/json",
2827
2844
  "x-api-key": publishableKey
2828
2845
  },
2829
- body: JSON.stringify({ events: fullEvents })
2846
+ body: JSON.stringify({ events: fullEvents }),
2847
+ keepalive: true
2830
2848
  }).catch((err) => {
2831
2849
  console.debug("[ScaleMule Analytics] Direct batch tracking failed:", err);
2832
2850
  });
package/dist/index.mjs CHANGED
@@ -2724,14 +2724,22 @@ function useAnalytics(options = {}) {
2724
2724
  const sendEvent = useCallback(
2725
2725
  async (event) => {
2726
2726
  const fullEvent = buildFullEvent(event);
2727
+ const payload = JSON.stringify(fullEvent);
2727
2728
  if (analyticsProxyUrl) {
2728
- fetch(analyticsProxyUrl, {
2729
- method: "POST",
2730
- headers: { "Content-Type": "application/json" },
2731
- body: JSON.stringify(fullEvent)
2732
- }).catch((err) => {
2733
- console.debug("[ScaleMule Analytics] Proxy tracking failed:", err);
2734
- });
2729
+ const sent = typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function" && navigator.sendBeacon(
2730
+ analyticsProxyUrl,
2731
+ new Blob([payload], { type: "application/json" })
2732
+ );
2733
+ if (!sent) {
2734
+ fetch(analyticsProxyUrl, {
2735
+ method: "POST",
2736
+ headers: { "Content-Type": "application/json" },
2737
+ body: payload,
2738
+ keepalive: true
2739
+ }).catch((err) => {
2740
+ console.debug("[ScaleMule Analytics] Proxy tracking failed:", err);
2741
+ });
2742
+ }
2735
2743
  return { tracked: 1, session_id: sessionIdRef.current || void 0 };
2736
2744
  }
2737
2745
  if (publishableKey && gatewayUrl) {
@@ -2742,7 +2750,8 @@ function useAnalytics(options = {}) {
2742
2750
  "Content-Type": "application/json",
2743
2751
  "x-api-key": publishableKey
2744
2752
  },
2745
- body: JSON.stringify(fullEvent)
2753
+ body: payload,
2754
+ keepalive: true
2746
2755
  }).catch((err) => {
2747
2756
  console.debug("[ScaleMule Analytics] Direct tracking failed:", err);
2748
2757
  });
@@ -2805,13 +2814,21 @@ function useAnalytics(options = {}) {
2805
2814
  const fullEvents = events.map((event) => buildFullEvent(event));
2806
2815
  if (analyticsProxyUrl) {
2807
2816
  for (const event of fullEvents) {
2808
- fetch(analyticsProxyUrl, {
2809
- method: "POST",
2810
- headers: { "Content-Type": "application/json" },
2811
- body: JSON.stringify(event)
2812
- }).catch((err) => {
2813
- console.debug("[ScaleMule Analytics] Proxy batch tracking failed:", err);
2814
- });
2817
+ const payload = JSON.stringify(event);
2818
+ const sent = typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function" && navigator.sendBeacon(
2819
+ analyticsProxyUrl,
2820
+ new Blob([payload], { type: "application/json" })
2821
+ );
2822
+ if (!sent) {
2823
+ fetch(analyticsProxyUrl, {
2824
+ method: "POST",
2825
+ headers: { "Content-Type": "application/json" },
2826
+ body: payload,
2827
+ keepalive: true
2828
+ }).catch((err) => {
2829
+ console.debug("[ScaleMule Analytics] Proxy batch tracking failed:", err);
2830
+ });
2831
+ }
2815
2832
  }
2816
2833
  setLoading(false);
2817
2834
  return { tracked: events.length, session_id: sessionIdRef.current || void 0 };
@@ -2824,7 +2841,8 @@ function useAnalytics(options = {}) {
2824
2841
  "Content-Type": "application/json",
2825
2842
  "x-api-key": publishableKey
2826
2843
  },
2827
- body: JSON.stringify({ events: fullEvents })
2844
+ body: JSON.stringify({ events: fullEvents }),
2845
+ keepalive: true
2828
2846
  }).catch((err) => {
2829
2847
  console.debug("[ScaleMule Analytics] Direct batch tracking failed:", err);
2830
2848
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/nextjs",
3
- "version": "0.0.27",
3
+ "version": "0.0.28",
4
4
  "description": "ScaleMule SDK for Next.js applications - authentication, storage, and user management",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",