@adstage/web-sdk 1.1.0 → 1.3.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/src/index.ts CHANGED
@@ -314,6 +314,23 @@ export class AdStageSDK {
314
314
  getAllSlots(): Map<string, AdSlot> {
315
315
  return new Map(this.slots);
316
316
  }
317
+
318
+ /**
319
+ * 커스텀 이벤트 추적
320
+ */
321
+ trackCustomEvent(eventName: string, params?: Record<string, any>): void {
322
+ try {
323
+ this.eventTracker.trackCustomEvent(eventName, {
324
+ timestamp: new Date().toISOString(),
325
+ ...params
326
+ });
327
+ if (this.config.debug) {
328
+ console.log(`📊 커스텀 이벤트 추적: ${eventName}`, params);
329
+ }
330
+ } catch (error) {
331
+ console.error('커스텀 이벤트 추적 실패:', error);
332
+ }
333
+ }
317
334
  }
318
335
 
319
336
  async function autoInit() {
@@ -346,5 +363,8 @@ export default AdStageSDK;
346
363
  export { AdType, AdEventType };
347
364
  export type { AdSlot, Advertisement };
348
365
 
349
- // React exports (통합)
350
- export * from './react';
366
+ // Standalone API (추천 사용법)
367
+ export * from './utils/sdk-standalone';
368
+
369
+ // React exports (React가 있을 때만 사용 - 레거시)
370
+ // export * from './react';
@@ -128,4 +128,52 @@ export class EventTracker {
128
128
 
129
129
  return 0; // 기본값
130
130
  }
131
+
132
+ /**
133
+ * 커스텀 이벤트 추적
134
+ */
135
+ async trackCustomEvent(eventName: string, params?: Record<string, any>): Promise<void> {
136
+ try {
137
+ // 디바이스 정보 수집
138
+ const deviceInfo = DeviceInfoCollector.collectDeviceInfo();
139
+
140
+ // 커스텀 이벤트 데이터 구성
141
+ const eventData = {
142
+ eventName,
143
+ params: params || {},
144
+
145
+ // 기본 메타데이터
146
+ userAgent: deviceInfo.userAgent,
147
+ platform: deviceInfo.platform,
148
+ screenWidth: deviceInfo.screenWidth,
149
+ screenHeight: deviceInfo.screenHeight,
150
+ deviceId: deviceInfo.deviceId,
151
+ sessionId: deviceInfo.sessionId,
152
+ timestamp: new Date().toISOString(),
153
+
154
+ // SDK 정보
155
+ sdkVersion: '1.3.1',
156
+ eventTimestamp: Date.now(),
157
+ };
158
+
159
+ // 커스텀 이벤트 API 엔드포인트로 전송
160
+ await fetch(
161
+ `${this.baseUrl}/events/custom`,
162
+ {
163
+ method: 'POST',
164
+ headers: {
165
+ 'x-api-key': this.apiKey,
166
+ 'Content-Type': 'application/json',
167
+ },
168
+ body: JSON.stringify(eventData),
169
+ }
170
+ );
171
+
172
+ if (this.debug) {
173
+ console.log(`📊 커스텀 이벤트 추적: ${eventName}`, eventData);
174
+ }
175
+ } catch (error) {
176
+ console.error('커스텀 이벤트 추적 실패:', error);
177
+ }
178
+ }
131
179
  }
@@ -0,0 +1,175 @@
1
+ /**
2
+ * AdStage SDK Standalone API
3
+ * 간단하고 직관적인 사용을 위한 통합 API
4
+ */
5
+
6
+ import type { AdType, AdSlotConfig } from '../types';
7
+
8
+ // 간단한 설정 인터페이스
9
+ export interface SimpleAdStageConfig {
10
+ apiKey: string;
11
+ debug?: boolean;
12
+ baseUrl?: string;
13
+ }
14
+
15
+ let globalSDKInstance: any = null;
16
+ let isInitializing = false;
17
+
18
+ /**
19
+ * SDK 초기화 (한 번만 호출)
20
+ */
21
+ export async function initAdStage(config: SimpleAdStageConfig): Promise<void> {
22
+ if (globalSDKInstance) {
23
+ console.warn('AdStage SDK가 이미 초기화되었습니다.');
24
+ return;
25
+ }
26
+
27
+ if (isInitializing) {
28
+ console.warn('AdStage SDK 초기화가 진행 중입니다.');
29
+ return;
30
+ }
31
+
32
+ isInitializing = true;
33
+
34
+ try {
35
+ // 동적 import로 circular dependency 방지
36
+ const { AdStageSDK } = await import('../index');
37
+ globalSDKInstance = AdStageSDK.init({
38
+ apiKey: config.apiKey,
39
+ debug: config.debug || false
40
+ });
41
+ console.log('✅ AdStage SDK 초기화 완료');
42
+ } catch (error) {
43
+ console.error('❌ AdStage SDK 초기화 실패:', error);
44
+ throw error;
45
+ } finally {
46
+ isInitializing = false;
47
+ }
48
+ }
49
+
50
+ /**
51
+ * 배너 광고 생성 (가장 간단한 API)
52
+ */
53
+ export async function createBanner(
54
+ containerId: string,
55
+ options?: {
56
+ width?: string | number;
57
+ height?: string | number;
58
+ autoSlide?: boolean;
59
+ slideInterval?: number;
60
+ }
61
+ ): Promise<void> {
62
+ if (!globalSDKInstance) {
63
+ throw new Error('AdStage SDK가 초기화되지 않았습니다. initAdStage()를 먼저 호출하세요.');
64
+ }
65
+
66
+ const slotId = `banner-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
67
+
68
+ return globalSDKInstance.createSlot(slotId, containerId, 'BANNER' as AdType, {
69
+ width: options?.width || '100%',
70
+ height: options?.height || 120,
71
+ autoSlideInterval: options?.autoSlide ? (options.slideInterval || 5) : 0,
72
+ sliderEffect: 'fade'
73
+ });
74
+ }
75
+
76
+ /**
77
+ * 텍스트 광고 생성
78
+ */
79
+ export async function createTextAd(
80
+ containerId: string,
81
+ options?: {
82
+ maxLines?: number;
83
+ style?: 'minimal' | 'card' | 'banner';
84
+ }
85
+ ): Promise<void> {
86
+ if (!globalSDKInstance) {
87
+ throw new Error('AdStage SDK가 초기화되지 않았습니다.');
88
+ }
89
+
90
+ const slotId = `text-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
91
+
92
+ return globalSDKInstance.createSlot(slotId, containerId, 'TEXT' as AdType, {
93
+ maxLines: options?.maxLines || 3,
94
+ style: options?.style || 'card'
95
+ });
96
+ }
97
+
98
+ /**
99
+ * 비디오 광고 생성
100
+ */
101
+ export async function createVideoAd(
102
+ containerId: string,
103
+ options?: {
104
+ width?: string | number;
105
+ height?: string | number;
106
+ autoplay?: boolean;
107
+ muted?: boolean;
108
+ }
109
+ ): Promise<void> {
110
+ if (!globalSDKInstance) {
111
+ throw new Error('AdStage SDK가 초기화되지 않았습니다.');
112
+ }
113
+
114
+ const slotId = `video-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
115
+
116
+ return globalSDKInstance.createSlot(slotId, containerId, 'VIDEO' as AdType, {
117
+ width: options?.width || '100%',
118
+ height: options?.height || 300,
119
+ autoplay: options?.autoplay || false,
120
+ muted: options?.muted || true
121
+ });
122
+ }
123
+
124
+ /**
125
+ * 커스텀 이벤트 추적
126
+ */
127
+ export function trackEvent(eventName: string, params?: Record<string, any>): void {
128
+ if (!globalSDKInstance) {
129
+ console.warn('AdStage SDK가 초기화되지 않았습니다. 이벤트 추적을 건너뜁니다.');
130
+ return;
131
+ }
132
+
133
+ try {
134
+ globalSDKInstance.trackCustomEvent(eventName, {
135
+ timestamp: new Date().toISOString(),
136
+ ...params
137
+ });
138
+ console.log(`📊 이벤트 추적: ${eventName}`, params);
139
+ } catch (error) {
140
+ console.error('이벤트 추적 실패:', error);
141
+ }
142
+ }
143
+
144
+ /**
145
+ * SDK 상태 확인
146
+ */
147
+ export function isAdStageReady(): boolean {
148
+ return globalSDKInstance !== null && !isInitializing;
149
+ }
150
+
151
+ /**
152
+ * SDK 인스턴스 가져오기 (고급 사용자용)
153
+ */
154
+ export function getAdStageInstance() {
155
+ if (!globalSDKInstance) {
156
+ console.warn('AdStage SDK가 초기화되지 않았습니다.');
157
+ return null;
158
+ }
159
+ return globalSDKInstance;
160
+ }
161
+
162
+ /**
163
+ * SDK 초기화 해제 (필요시)
164
+ */
165
+ export function destroyAdStage(): void {
166
+ if (globalSDKInstance) {
167
+ try {
168
+ // SDK cleanup logic here
169
+ globalSDKInstance = null;
170
+ console.log('🧹 AdStage SDK 정리 완료');
171
+ } catch (error) {
172
+ console.error('SDK 정리 중 오류:', error);
173
+ }
174
+ }
175
+ }