@adstage/web-sdk
Version:
AdStage Web SDK - Production-ready marketing platform SDK with React Provider support for seamless integration
58 lines (53 loc) • 1.99 kB
text/typescript
import { AdEventType } from '../../types/advertisement';
import type { Advertisement, AdSlot } from '../../types/advertisement';
/**
* 슬라이더 이벤트 추적 공통 유틸리티
* - 모든 슬라이더 타입에서 일관된 VIEWABLE 이벤트 추적
* - 중복 방지는 상위 레벨에서 처리
*/
export class SliderEventTracker {
/**
* 슬라이드 변경 시 VIEWABLE 이벤트 추적
* @param advertisement 현재 슬라이드의 광고
* @param slot 광고 슬롯
* @param slideIndex 현재 슬라이드 인덱스
* @param trackEventCallback 이벤트 추적 콜백
* @param debug 디버그 모드
*/
static trackSlideViewable(
advertisement: Advertisement,
slot: AdSlot,
slideIndex: number,
trackEventCallback: (adId: string, slotId: string, eventType: AdEventType) => void,
debug: boolean = false
): void {
if (debug) {
console.log(
`🎯 Triggering VIEWABLE event for slide change: ad ${advertisement._id} (index: ${slideIndex}) in slot: ${slot.id}`
);
}
// 모든 슬라이드에 대해 VIEWABLE 이벤트 추적 (첫 번째 포함)
trackEventCallback(advertisement._id, slot.id, AdEventType.VIEWABLE);
}
/**
* 초기 슬라이드 로딩 시 VIEWABLE 이벤트 추적
* @param advertisement 첫 번째 슬라이드의 광고
* @param slot 광고 슬롯
* @param trackEventCallback 이벤트 추적 콜백
* @param debug 디버그 모드
*/
static trackInitialSlideViewable(
advertisement: Advertisement,
slot: AdSlot,
trackEventCallback: (adId: string, slotId: string, eventType: AdEventType) => void,
debug: boolean = false
): void {
if (debug) {
console.log(
`🎯 Triggering initial VIEWABLE event: ad ${advertisement._id} (index: 0) in slot: ${slot.id}`
);
}
// 첫 번째 슬라이드도 동일하게 추적
trackEventCallback(advertisement._id, slot.id, AdEventType.VIEWABLE);
}
}