@adstage/web-sdk 3.0.7 → 3.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adstage/web-sdk",
3
- "version": "3.0.7",
3
+ "version": "3.0.9",
4
4
  "description": "AdStage Web SDK - Production-ready marketing platform SDK with React Provider support for seamless integration",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
@@ -105,18 +105,33 @@ export class AdStage {
105
105
  }
106
106
 
107
107
  /**
108
- * 편의성을 위한 정적 모듈 접근자들
108
+ * 편의성을 위한 정적 모듈 접근자들 (안전장치 포함)
109
109
  */
110
110
  public static get ads() {
111
- return AdStage.getInstance().ads;
111
+ try {
112
+ return AdStage.getInstance().ads;
113
+ } catch (error) {
114
+ console.warn('AdStage.ads accessed before initialization');
115
+ throw error;
116
+ }
112
117
  }
113
118
 
114
119
  public static get events() {
115
- return AdStage.getInstance().events;
120
+ try {
121
+ return AdStage.getInstance().events;
122
+ } catch (error) {
123
+ console.warn('AdStage.events accessed before initialization');
124
+ throw error;
125
+ }
116
126
  }
117
127
 
118
128
  public static get config() {
119
- return AdStage.getInstance().config;
129
+ try {
130
+ return AdStage.getInstance().config;
131
+ } catch (error) {
132
+ console.warn('AdStage.config accessed before initialization');
133
+ throw error;
134
+ }
120
135
  }
121
136
 
122
137
  /**
@@ -49,6 +49,16 @@ export class AdvertisementEventTracker {
49
49
  return;
50
50
  }
51
51
 
52
+ // DOM 요소가 실제로 존재하는지 확인 (이미 제거된 요소에 대한 추적 방지)
53
+ const element = document.getElementById(slot.containerId) ||
54
+ document.querySelector(`[data-adstage-slot-id="${slotId}"]`);
55
+ if (!element) {
56
+ if (this.debug) {
57
+ console.warn(`⚠️ DOM element not found for slotId: ${slotId} (containerId: ${slot.containerId}). Skipping event tracking.`);
58
+ }
59
+ return;
60
+ }
61
+
52
62
  // 디바이스 정보 수집
53
63
  const deviceInfo = DeviceInfoCollector.collectDeviceInfo();
54
64
 
@@ -119,9 +119,26 @@ export class DeviceInfoCollector {
119
119
 
120
120
  /**
121
121
  * 슬롯 위치 정보 가져오기 (SSR 안전)
122
+ * 슬라이더 내부 광고 요소도 지원
122
123
  */
123
124
  static getSlotPosition(containerId: string): string {
124
- const element = DOMUtils.safeGetElementById(containerId);
125
+ // 1. 기본 컨테이너 ID로 먼저 찾기
126
+ let element = DOMUtils.safeGetElementById(containerId);
127
+
128
+ // 2. 컨테이너를 찾지 못한 경우, 슬라이더 래퍼 찾기
129
+ if (!element) {
130
+ // 슬라이더 래퍼는 일반적으로 원본 컨테이너 내부에 있음
131
+ const sliderWrapper = DOMUtils.safeQuerySelector(`#${containerId} .adstage-slider-wrapper`);
132
+ if (sliderWrapper) {
133
+ element = sliderWrapper as HTMLElement;
134
+ }
135
+ }
136
+
137
+ // 3. 여전히 찾지 못한 경우, data-adstage-slot-id 속성으로 찾기
138
+ if (!element) {
139
+ element = DOMUtils.safeQuerySelector(`[data-adstage-slot-id="${containerId}"]`);
140
+ }
141
+
125
142
  if (!element) return 'unknown';
126
143
 
127
144
  const rect = element.getBoundingClientRect();
@@ -211,7 +211,11 @@ export class AdsModule implements BaseModule {
211
211
 
212
212
  const slot = this.slots.get(slotId);
213
213
  if (!slot) {
214
- throw new Error(`Ad slot not found: ${slotId}`);
214
+ // 🔧 이미 정리된 슬롯인 경우 조용히 처리 (에러 발생하지 않음)
215
+ if (this._config?.debug) {
216
+ console.log(`🔍 Ad slot already cleaned up: ${slotId}`);
217
+ }
218
+ return;
215
219
  }
216
220
 
217
221
  // SimpleViewabilityTracker 정리
@@ -637,6 +641,11 @@ export class AdsModule implements BaseModule {
637
641
  const slot = this.slots.get(slotId);
638
642
  if (slot) {
639
643
  try {
644
+ // SimpleViewabilityTracker 정리
645
+ if ((slot as any).viewabilityTracker) {
646
+ (slot as any).viewabilityTracker.destroy();
647
+ }
648
+
640
649
  // 슬롯 정리 (로그 출력 최소화)
641
650
  this.slots.delete(slotId);
642
651