@ai-ad-network/frontend-sdk 1.1.5 → 1.1.7
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/hooks/useAiAds.d.ts +5 -3
- package/dist/index.esm.js +31 -16
- package/dist/index.js +31 -16
- package/dist/version.d.ts +1 -1
- package/package.json +1 -1
package/dist/hooks/useAiAds.d.ts
CHANGED
|
@@ -23,14 +23,16 @@ import type { KoahAd, IntentResult, RoutingInfo, UseAiAdsOptions, UseAiAdsResult
|
|
|
23
23
|
*/
|
|
24
24
|
export declare function useAiAds(userQuery: string, aiResponse: string, isStreamFinished: boolean, options?: UseAiAdsOptions): UseAiAdsResult;
|
|
25
25
|
/**
|
|
26
|
-
* 🆕 useAiadsWithAnalytics -
|
|
26
|
+
* 🆕 useAiadsWithAnalytics - Alias for useAiAds for semantic clarity
|
|
27
27
|
*
|
|
28
|
-
* This
|
|
29
|
-
*
|
|
28
|
+
* This is an alias for useAiAds, included for semantic clarity.
|
|
29
|
+
* Both hooks now automatically store analytics data globally
|
|
30
|
+
* for simplified components (ActionCardAd, EntityLinkAd, etc.).
|
|
30
31
|
*
|
|
31
32
|
* @example
|
|
32
33
|
* ```tsx
|
|
33
34
|
* function ChatApp() {
|
|
35
|
+
* // useAiadsWithAnalytics makes it explicit that analytics will be available
|
|
34
36
|
* const { ads } = useAiadsWithAnalytics(query, response, isFinished);
|
|
35
37
|
*
|
|
36
38
|
* return ads.map(ad => (
|
package/dist/index.esm.js
CHANGED
|
@@ -3,7 +3,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import React, { useMemo, useState, useRef, useCallback, useEffect, createContext, useContext, Component } from "react";
|
|
5
5
|
import useSWR from "swr";
|
|
6
|
-
const SDK_VERSION = "1.1.
|
|
6
|
+
const SDK_VERSION = "1.1.7";
|
|
7
7
|
var IntentType = /* @__PURE__ */ ((IntentType2) => {
|
|
8
8
|
IntentType2["SHOPPING"] = "shopping";
|
|
9
9
|
IntentType2["LEAD_GEN"] = "lead_gen";
|
|
@@ -707,6 +707,35 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
707
707
|
setRequestId(data.requestId);
|
|
708
708
|
}
|
|
709
709
|
setSlotsMap(slotsMapData);
|
|
710
|
+
if ((data == null ? void 0 : data.requestId) && typeof window !== "undefined") {
|
|
711
|
+
window.__AD_ANALYTICS__ = {
|
|
712
|
+
requestId: data.requestId,
|
|
713
|
+
slotsMap: slotsMapData,
|
|
714
|
+
getAdAnalytics: (adId, slotId) => {
|
|
715
|
+
if (slotId) {
|
|
716
|
+
const slotInfo = slotsMapData[slotId];
|
|
717
|
+
if (!slotInfo) return null;
|
|
718
|
+
const position = slotInfo.ads.findIndex((ad) => ad.id === adId);
|
|
719
|
+
if (position === -1) return null;
|
|
720
|
+
return { requestId: data.requestId, slotId, position, totalAds: slotInfo.count };
|
|
721
|
+
}
|
|
722
|
+
for (const [sid, slotInfo] of Object.entries(slotsMapData)) {
|
|
723
|
+
const info = slotInfo;
|
|
724
|
+
const position = info.ads.findIndex((ad) => ad.id === adId);
|
|
725
|
+
if (position !== -1) {
|
|
726
|
+
return { requestId: data.requestId, slotId: sid, position, totalAds: info.count };
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
return null;
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
if (process.env.NODE_ENV === "development") {
|
|
733
|
+
console.log("[useAiAds] Analytics data stored globally for simplified components", {
|
|
734
|
+
requestId: data.requestId,
|
|
735
|
+
slotsMap: Object.keys(slotsMapData)
|
|
736
|
+
});
|
|
737
|
+
}
|
|
738
|
+
}
|
|
710
739
|
if (convertedAds.length > 0) {
|
|
711
740
|
setAds(convertedAds);
|
|
712
741
|
hasRequestedRef.current = true;
|
|
@@ -749,21 +778,7 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
749
778
|
};
|
|
750
779
|
}
|
|
751
780
|
function useAiadsWithAnalytics(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
752
|
-
|
|
753
|
-
const { requestId, slotsMap, getAdAnalytics } = result;
|
|
754
|
-
useEffect(() => {
|
|
755
|
-
if (requestId && typeof window !== "undefined") {
|
|
756
|
-
window.__AD_ANALYTICS__ = {
|
|
757
|
-
requestId,
|
|
758
|
-
slotsMap,
|
|
759
|
-
getAdAnalytics
|
|
760
|
-
};
|
|
761
|
-
if (process.env.NODE_ENV === "development") {
|
|
762
|
-
console.log("[useAiAds] Analytics data stored globally for simplified components");
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
}, [requestId, slotsMap, getAdAnalytics]);
|
|
766
|
-
return result;
|
|
781
|
+
return useAiAds(userQuery, aiResponse, isStreamFinished, options);
|
|
767
782
|
}
|
|
768
783
|
function useAiAdsLazy(options = {}) {
|
|
769
784
|
const stableOptions = useStableOptions(options);
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
5
5
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
6
|
const React = require("react");
|
|
7
7
|
const useSWR = require("swr");
|
|
8
|
-
const SDK_VERSION = "1.1.
|
|
8
|
+
const SDK_VERSION = "1.1.7";
|
|
9
9
|
var IntentType = /* @__PURE__ */ ((IntentType2) => {
|
|
10
10
|
IntentType2["SHOPPING"] = "shopping";
|
|
11
11
|
IntentType2["LEAD_GEN"] = "lead_gen";
|
|
@@ -709,6 +709,35 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
709
709
|
setRequestId(data.requestId);
|
|
710
710
|
}
|
|
711
711
|
setSlotsMap(slotsMapData);
|
|
712
|
+
if ((data == null ? void 0 : data.requestId) && typeof window !== "undefined") {
|
|
713
|
+
window.__AD_ANALYTICS__ = {
|
|
714
|
+
requestId: data.requestId,
|
|
715
|
+
slotsMap: slotsMapData,
|
|
716
|
+
getAdAnalytics: (adId, slotId) => {
|
|
717
|
+
if (slotId) {
|
|
718
|
+
const slotInfo = slotsMapData[slotId];
|
|
719
|
+
if (!slotInfo) return null;
|
|
720
|
+
const position = slotInfo.ads.findIndex((ad) => ad.id === adId);
|
|
721
|
+
if (position === -1) return null;
|
|
722
|
+
return { requestId: data.requestId, slotId, position, totalAds: slotInfo.count };
|
|
723
|
+
}
|
|
724
|
+
for (const [sid, slotInfo] of Object.entries(slotsMapData)) {
|
|
725
|
+
const info = slotInfo;
|
|
726
|
+
const position = info.ads.findIndex((ad) => ad.id === adId);
|
|
727
|
+
if (position !== -1) {
|
|
728
|
+
return { requestId: data.requestId, slotId: sid, position, totalAds: info.count };
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return null;
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
if (process.env.NODE_ENV === "development") {
|
|
735
|
+
console.log("[useAiAds] Analytics data stored globally for simplified components", {
|
|
736
|
+
requestId: data.requestId,
|
|
737
|
+
slotsMap: Object.keys(slotsMapData)
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
}
|
|
712
741
|
if (convertedAds.length > 0) {
|
|
713
742
|
setAds(convertedAds);
|
|
714
743
|
hasRequestedRef.current = true;
|
|
@@ -751,21 +780,7 @@ function useAiAds(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
|
751
780
|
};
|
|
752
781
|
}
|
|
753
782
|
function useAiadsWithAnalytics(userQuery, aiResponse, isStreamFinished, options = {}) {
|
|
754
|
-
|
|
755
|
-
const { requestId, slotsMap, getAdAnalytics } = result;
|
|
756
|
-
React.useEffect(() => {
|
|
757
|
-
if (requestId && typeof window !== "undefined") {
|
|
758
|
-
window.__AD_ANALYTICS__ = {
|
|
759
|
-
requestId,
|
|
760
|
-
slotsMap,
|
|
761
|
-
getAdAnalytics
|
|
762
|
-
};
|
|
763
|
-
if (process.env.NODE_ENV === "development") {
|
|
764
|
-
console.log("[useAiAds] Analytics data stored globally for simplified components");
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
|
-
}, [requestId, slotsMap, getAdAnalytics]);
|
|
768
|
-
return result;
|
|
783
|
+
return useAiAds(userQuery, aiResponse, isStreamFinished, options);
|
|
769
784
|
}
|
|
770
785
|
function useAiAdsLazy(options = {}) {
|
|
771
786
|
const stableOptions = useStableOptions(options);
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.1.
|
|
1
|
+
export declare const SDK_VERSION = "1.1.7";
|