@ai-ad-network/frontend-sdk 1.0.9 → 1.1.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/analytics/index.d.ts +99 -0
- package/dist/components/ActionCardAd.d.ts +34 -0
- package/dist/components/AdProvider.d.ts +2 -2
- package/dist/hooks/useAdSlots.d.ts +4 -3
- package/dist/hooks/useAdTracking.d.ts +38 -0
- package/dist/hooks/useAiAds.d.ts +4 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.esm.js +787 -195
- package/dist/index.js +787 -195
- package/dist/types/analytics.d.ts +96 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/universal/index.d.ts +293 -9
- package/dist/universal/universal.cjs.js +632 -7
- package/dist/universal/universal.cjs.js.map +1 -1
- package/dist/universal/universal.esm.js +633 -8
- package/dist/universal/universal.esm.js.map +1 -1
- package/dist/universal/universal.iife.js +632 -7
- package/dist/universal/universal.iife.js.map +1 -1
- package/dist/universal/universal.umd.js +632 -7
- package/dist/universal/universal.umd.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/docs/AD_FORMATS.md +521 -154
- package/docs/ANALYTICS_UPGRADE_SUMMARY.md +301 -0
- package/docs/FRONTEND_SDK_ANALYTICS_UPGRADE.md +1152 -0
- package/docs/SDK_ISSUES_ANALYSIS.md +380 -0
- package/package.json +1 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics API - 框架无关的核心模块
|
|
3
|
+
*
|
|
4
|
+
* React 和 Universal SDK 共享此模块
|
|
5
|
+
* 用于发送广告展示和点击事件到 Backend Analytics API
|
|
6
|
+
*/
|
|
7
|
+
import type { ImpressionEventData, ClickEventData, ImpressionResponse, ClickResponse, SessionConfig, AnalyticsSendConfig } from '../types/analytics';
|
|
8
|
+
/**
|
|
9
|
+
* Session 管理器
|
|
10
|
+
*/
|
|
11
|
+
export declare class SessionManager {
|
|
12
|
+
private sessionKey;
|
|
13
|
+
private storage;
|
|
14
|
+
private memoryCache;
|
|
15
|
+
constructor(config?: SessionConfig);
|
|
16
|
+
/**
|
|
17
|
+
* 获取 Session ID
|
|
18
|
+
*/
|
|
19
|
+
getSessionId(): string;
|
|
20
|
+
/**
|
|
21
|
+
* 重新生成 Session ID
|
|
22
|
+
*/
|
|
23
|
+
regenerateSessionId(): string;
|
|
24
|
+
/**
|
|
25
|
+
* 生成新的 Session ID
|
|
26
|
+
*/
|
|
27
|
+
private generateSessionId;
|
|
28
|
+
/**
|
|
29
|
+
* 清除 Session ID
|
|
30
|
+
*/
|
|
31
|
+
clearSessionId(): void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 获取 Session ID(便捷方法)
|
|
35
|
+
*/
|
|
36
|
+
export declare const getSessionId: () => string;
|
|
37
|
+
/**
|
|
38
|
+
* Analytics 发送器类
|
|
39
|
+
*/
|
|
40
|
+
export declare class AnalyticsSender {
|
|
41
|
+
private baseUrl;
|
|
42
|
+
private timeout;
|
|
43
|
+
private retryAttempts;
|
|
44
|
+
private retryDelay;
|
|
45
|
+
private debug;
|
|
46
|
+
constructor(config?: AnalyticsSendConfig);
|
|
47
|
+
/**
|
|
48
|
+
* 发送广告展示事件
|
|
49
|
+
*/
|
|
50
|
+
trackImpression(data: ImpressionEventData): Promise<ImpressionResponse | null>;
|
|
51
|
+
/**
|
|
52
|
+
* 发送广告点击事件
|
|
53
|
+
*/
|
|
54
|
+
trackClick(data: ClickEventData): Promise<ClickResponse | null>;
|
|
55
|
+
/**
|
|
56
|
+
* 通用请求发送方法(带重试)
|
|
57
|
+
*/
|
|
58
|
+
private sendRequest;
|
|
59
|
+
/**
|
|
60
|
+
* 延迟辅助方法
|
|
61
|
+
*/
|
|
62
|
+
private delay;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 发送广告展示事件(便捷方法)
|
|
66
|
+
*/
|
|
67
|
+
export declare const trackAdImpression: (data: ImpressionEventData) => Promise<ImpressionResponse | null>;
|
|
68
|
+
/**
|
|
69
|
+
* 发送广告点击事件(便捷方法)
|
|
70
|
+
*/
|
|
71
|
+
export declare const trackAdClick: (data: ClickEventData) => Promise<ClickResponse | null>;
|
|
72
|
+
/**
|
|
73
|
+
* 生成 View Token(用于展示去重)
|
|
74
|
+
*/
|
|
75
|
+
export declare function generateViewToken(adId: string, sessionId: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* 批量发送展示事件
|
|
78
|
+
*/
|
|
79
|
+
export declare function trackImpressionsBatch(events: ImpressionEventData[]): Promise<(ImpressionResponse | null)[]>;
|
|
80
|
+
/**
|
|
81
|
+
* 批量发送点击事件
|
|
82
|
+
*/
|
|
83
|
+
export declare function trackClicksBatch(events: ClickEventData[]): Promise<(ClickResponse | null)[]>;
|
|
84
|
+
/**
|
|
85
|
+
* 创建带配置的 Analytics 实例
|
|
86
|
+
*/
|
|
87
|
+
export declare function createAnalytics(config: AnalyticsSendConfig): {
|
|
88
|
+
trackImpression: (data: ImpressionEventData) => Promise<ImpressionResponse | null>;
|
|
89
|
+
trackClick: (data: ClickEventData) => Promise<ClickResponse | null>;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* 创建带配置的 Session 实例
|
|
93
|
+
*/
|
|
94
|
+
export declare function createSession(config?: SessionConfig): {
|
|
95
|
+
getSessionId: () => string;
|
|
96
|
+
regenerateSessionId: () => string;
|
|
97
|
+
clearSessionId: () => void;
|
|
98
|
+
};
|
|
99
|
+
export type { ImpressionEventData, ClickEventData, ImpressionResponse, ClickResponse, SessionConfig, AnalyticsSendConfig, };
|
|
@@ -24,3 +24,37 @@ export interface ActionCardAdProps {
|
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
export declare function ActionCardAd({ ad, variant, className, isLoading, onClick, onImpression, }: ActionCardAdProps): import("react/jsx-runtime").JSX.Element | null;
|
|
27
|
+
/**
|
|
28
|
+
* ActionCardAdV2 Props
|
|
29
|
+
*/
|
|
30
|
+
export interface ActionCardAdV2Props {
|
|
31
|
+
ad: KoahAd;
|
|
32
|
+
variant?: ActionCardVariant;
|
|
33
|
+
className?: string;
|
|
34
|
+
isLoading?: boolean;
|
|
35
|
+
requestId: string;
|
|
36
|
+
slotId: string;
|
|
37
|
+
position: number;
|
|
38
|
+
totalAds: number;
|
|
39
|
+
onClick?: () => void;
|
|
40
|
+
onImpression?: () => void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* ActionCardAdV2 - Action Card component with Analytics API tracking
|
|
44
|
+
*
|
|
45
|
+
* Uses the new Analytics API (POST /api/v1/ads/impression, POST /api/v1/ads/click)
|
|
46
|
+
* instead of pixel tracking.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```tsx
|
|
50
|
+
* <ActionCardAdV2
|
|
51
|
+
* ad={ad}
|
|
52
|
+
* requestId="req-123"
|
|
53
|
+
* slotId="slot-action-card"
|
|
54
|
+
* position={0}
|
|
55
|
+
* totalAds={3}
|
|
56
|
+
* variant="horizontal"
|
|
57
|
+
* />
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare function ActionCardAdV2({ ad, variant, className, isLoading, requestId, slotId, position, totalAds, onClick, onImpression, }: ActionCardAdV2Props): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -5,7 +5,7 @@ import React, { ReactNode } from 'react';
|
|
|
5
5
|
export interface AdConfig {
|
|
6
6
|
/** Base URL for API requests */
|
|
7
7
|
apiBaseUrl?: string;
|
|
8
|
-
/** API Key for authentication (format:
|
|
8
|
+
/** API Key for authentication (format: ak_<name>_<tier>_<hash>) */
|
|
9
9
|
apiKey?: string;
|
|
10
10
|
/** Default ad formats to request */
|
|
11
11
|
defaultFormats?: string[];
|
|
@@ -57,7 +57,7 @@ export interface AdProviderProps {
|
|
|
57
57
|
* <AdProvider
|
|
58
58
|
* config={{
|
|
59
59
|
* apiBaseUrl: 'https://api.example.com/v1',
|
|
60
|
-
* apiKey: '
|
|
60
|
+
* apiKey: 'ak_chatbox_growth_k8Hj3mN9pQ2rT5vY8xZ1cD4fG6hJ9kLm',
|
|
61
61
|
* enabled: true,
|
|
62
62
|
* debug: process.env.NODE_ENV === 'development',
|
|
63
63
|
* }}
|
|
@@ -137,7 +137,7 @@ export declare function useChatWithAds(options: {
|
|
|
137
137
|
* Automatically injects client information for OpenRTB compliance.
|
|
138
138
|
*
|
|
139
139
|
* @param params - Ad request parameters
|
|
140
|
-
* @param options - Additional options (apiBaseUrl, etc.)
|
|
140
|
+
* @param options - Additional options (apiBaseUrl, apiKey, etc.)
|
|
141
141
|
* @returns Promise resolving to ad response batch
|
|
142
142
|
*
|
|
143
143
|
* @example
|
|
@@ -150,7 +150,7 @@ export declare function useChatWithAds(options: {
|
|
|
150
150
|
* { slotId: 'slot-source', format: 'source', ... },
|
|
151
151
|
* { slotId: 'slot-static', format: 'static', ... }
|
|
152
152
|
* ]
|
|
153
|
-
* });
|
|
153
|
+
* }, { apiKey: 'ak_xxx' });
|
|
154
154
|
*
|
|
155
155
|
* // Post-response stage (query + response available)
|
|
156
156
|
* const postResponse = await fetchAds({
|
|
@@ -167,7 +167,7 @@ export declare function useChatWithAds(options: {
|
|
|
167
167
|
* { slotId: 'slot-suffix', format: 'suffix', ... },
|
|
168
168
|
* { slotId: 'slot-action_card', format: 'action_card', ... }
|
|
169
169
|
* ]
|
|
170
|
-
* });
|
|
170
|
+
* }, { apiKey: 'ak_xxx' });
|
|
171
171
|
* ```
|
|
172
172
|
*/
|
|
173
173
|
export declare function fetchAds(params: {
|
|
@@ -176,4 +176,5 @@ export declare function fetchAds(params: {
|
|
|
176
176
|
slots: AdSlotRequest[];
|
|
177
177
|
}, options?: {
|
|
178
178
|
apiBaseUrl?: string;
|
|
179
|
+
apiKey?: string;
|
|
179
180
|
}): Promise<AdResponseBatch>;
|
|
@@ -57,3 +57,41 @@ export declare function useClickTracking(ad: KoahAd | null, options?: Pick<AdTra
|
|
|
57
57
|
handleClick: (e: React.MouseEvent | MouseEvent) => void;
|
|
58
58
|
isClicking: boolean;
|
|
59
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* useAdTrackingV2 - Hook for ad impression and click tracking with Analytics API
|
|
62
|
+
*
|
|
63
|
+
* Uses the new Analytics API (POST /api/v1/ads/impression, POST /api/v1/ads/click)
|
|
64
|
+
* instead of pixel tracking.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```tsx
|
|
68
|
+
* const { impressionRef, handleClick, hasImpressed } = useAdTrackingV2<HTMLDivElement>({
|
|
69
|
+
* ad,
|
|
70
|
+
* requestId: 'req-123',
|
|
71
|
+
* slotId: 'slot-action-card',
|
|
72
|
+
* position: 0,
|
|
73
|
+
* totalAds: 3,
|
|
74
|
+
* onImpression: () => console.log('Ad viewed!'),
|
|
75
|
+
* onClick: () => console.log('Ad clicked!'),
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export interface UseAdTrackingV2Params {
|
|
80
|
+
ad: KoahAd;
|
|
81
|
+
requestId: string;
|
|
82
|
+
slotId: string;
|
|
83
|
+
position: number;
|
|
84
|
+
totalAds: number;
|
|
85
|
+
intersectionThreshold?: number;
|
|
86
|
+
minViewTimeMs?: number;
|
|
87
|
+
onClick?: () => void;
|
|
88
|
+
onImpression?: () => void;
|
|
89
|
+
}
|
|
90
|
+
export interface UseAdTrackingV2Result {
|
|
91
|
+
impressionRef: React.RefObject<HTMLElement>;
|
|
92
|
+
handleClick: (e: React.MouseEvent) => void;
|
|
93
|
+
hasImpressed: boolean;
|
|
94
|
+
isIntersecting: boolean;
|
|
95
|
+
impressionTrackingSent: boolean;
|
|
96
|
+
}
|
|
97
|
+
export declare function useAdTrackingV2<T extends HTMLElement = HTMLDivElement>(params: UseAdTrackingV2Params): UseAdTrackingV2Result;
|
package/dist/hooks/useAiAds.d.ts
CHANGED
|
@@ -7,6 +7,8 @@ import type { KoahAd, IntentResult, RoutingInfo, UseAiAdsOptions, UseAiAdsResult
|
|
|
7
7
|
* 2. A user query is present
|
|
8
8
|
* 3. The hook is enabled
|
|
9
9
|
*
|
|
10
|
+
* Uses the unified /api/v1/ads/request endpoint with auto-injected ClientInfo.
|
|
11
|
+
*
|
|
10
12
|
* @example
|
|
11
13
|
* ```tsx
|
|
12
14
|
* const { ads, intent, isLoading, error } = useAiAds(
|
|
@@ -21,6 +23,8 @@ export declare function useAiAds(userQuery: string, aiResponse: string, isStream
|
|
|
21
23
|
/**
|
|
22
24
|
* useAiAdsLazy - Lazy variant that fetches on demand
|
|
23
25
|
*
|
|
26
|
+
* Uses the unified /api/v1/ads/request endpoint with auto-injected ClientInfo.
|
|
27
|
+
*
|
|
24
28
|
* @example
|
|
25
29
|
* ```tsx
|
|
26
30
|
* const { fetchAds, ads, isLoading } = useAiAdsLazy();
|
package/dist/index.d.ts
CHANGED
|
@@ -27,10 +27,12 @@ export * from './types';
|
|
|
27
27
|
export type { ConversationMessage, UserProfile, ResponseMetadata, SlotDecisionMetadata, } from './types';
|
|
28
28
|
export { useAiAds, useAiAdsLazy, useAiAdsInfinite } from './hooks/useAiAds';
|
|
29
29
|
export { useAdSlots, useAdSlot, useChatWithAds, adaptAdToKoahAd, fetchAds } from './hooks/useAdSlots';
|
|
30
|
-
export { useAdTracking, useAdTrackingMultiple, useClickTracking, } from './hooks/useAdTracking';
|
|
30
|
+
export { useAdTracking, useAdTrackingV2, useAdTrackingMultiple, useClickTracking, } from './hooks/useAdTracking';
|
|
31
|
+
export type { UseAdTrackingV2Params, UseAdTrackingV2Result, } from './hooks/useAdTracking';
|
|
31
32
|
export { useAdConfig } from './components/AdProvider';
|
|
32
33
|
export { AdLogger, createLogger } from './components/AdProvider';
|
|
33
|
-
export { ActionCardAd } from './components/ActionCardAd';
|
|
34
|
+
export { ActionCardAd, ActionCardAdV2 } from './components/ActionCardAd';
|
|
35
|
+
export type { ActionCardAdV2Props } from './components/ActionCardAd';
|
|
34
36
|
export { EnhancedContent, EnhancedContentInline, EnhancedContentBlock, useEntityStats, } from './components/EnhancedContent';
|
|
35
37
|
export { SuffixAd, SuffixAdInline, SuffixAdMinimal, } from './components/SuffixAd';
|
|
36
38
|
export { FollowUpAd, FollowUpAdMixed, } from './components/FollowUpAd';
|
|
@@ -44,6 +46,8 @@ export { AdProvider } from './components/AdProvider';
|
|
|
44
46
|
export { AdErrorBoundary, withAdErrorBoundary, AdErrorHandler, } from './components/AdErrorBoundary';
|
|
45
47
|
export { AdSkeleton, InlineLoading, DotsLoading, FullPageLoading, } from './components/AdSkeleton';
|
|
46
48
|
export { trackImpression, trackClick, hashUserId, checkFrequencyControl, recordImpression, getSessionId, } from './utils/tracking';
|
|
49
|
+
export { trackAdImpression, trackAdClick, trackImpressionsBatch, trackClicksBatch, generateViewToken, getSessionId as getAnalyticsSessionId, SessionManager, AnalyticsSender, createAnalytics, createSession, } from './analytics';
|
|
50
|
+
export type { ImpressionEventData, ClickEventData, ImpressionResponse, ClickResponse, AdAnalyticsInfo, AdSlotInfo, SessionConfig, AnalyticsSendConfig, } from './types/analytics';
|
|
47
51
|
export { textWeaver, TextWeaver } from './utils/text-weaver';
|
|
48
52
|
export { cn } from './lib/cn';
|
|
49
53
|
export { ClientInfoCollector, getClientInfoCollector, getClientInfo, getDeviceInfo, getUserInfo, getAppInfo, getGeoInfo, getUserId, clearClientInfoCache, getClientInfoJSON, getClientInfoSummary, } from './client-info';
|