@adstage/web-sdk 3.0.1 → 3.0.3

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.1",
3
+ "version": "3.0.3",
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",
@@ -25,7 +25,8 @@
25
25
  ],
26
26
  "scripts": {
27
27
  "build:types": "tsc --project tsconfig.types.json",
28
- "build": "npm run build:types && rollup -c",
28
+ "build": "npm run build:types && NODE_ENV=production rollup -c",
29
+ "build:dev": "npm run build:types && rollup -c",
29
30
  "build:watch": "rollup -c -w",
30
31
  "dev": "rollup -c -w",
31
32
  "clean": "rm -rf dist dist-types",
@@ -65,8 +66,10 @@
65
66
  "@rollup/plugin-typescript": "^11.1.0",
66
67
  "@types/node": "^20.0.0",
67
68
  "@types/react": "^18.0.0",
69
+ "javascript-obfuscator": "^4.1.1",
68
70
  "rollup": "^3.23.0",
69
71
  "rollup-plugin-dts": "^5.3.0",
72
+ "rollup-plugin-obfuscator": "^1.1.0",
70
73
  "tslib": "^2.8.1",
71
74
  "typescript": "^5.0.0"
72
75
  },
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import AdStage from '../core/adstage';
7
- import type { EventProperties, PageData } from '../modules/events/events-module';
7
+ import type { EventProperties } from '../modules/events/events-module';
8
8
 
9
9
  /**
10
10
  * 이벤트 추적 (메인 함수)
@@ -27,46 +27,64 @@ export function track(eventName: string, properties?: EventProperties): Promise<
27
27
  return AdStage.events.track(eventName, properties);
28
28
  }
29
29
 
30
+
31
+
30
32
  /**
31
- * 페이지 추적
32
- * @param pageData 페이지 정보
33
+ * 사용자 ID 설정
34
+ * @param userId 사용자 ID
33
35
  *
34
36
  * @example
35
- * pageView({ page: '/products', title: 'Products Page' });
37
+ * setUserId('user123');
36
38
  */
37
- export function pageView(pageData?: PageData): Promise<void> {
39
+ export function setUserId(userId: string): void {
38
40
  if (!AdStage.isReady()) {
39
41
  console.warn('AdStage not initialized. Call AdStage.init() first.');
40
- return Promise.resolve();
42
+ return;
41
43
  }
42
44
 
43
- return AdStage.events.pageView(pageData);
45
+ AdStage.events.setUserId(userId);
44
46
  }
45
47
 
46
48
  /**
47
- * 사용자 ID 설정
48
- * @param userId 사용자 ID
49
+ * 현재 사용자 ID 반환
50
+ */
51
+ export function getUserId(): string | undefined {
52
+ if (!AdStage.isReady()) {
53
+ console.warn('AdStage not initialized. Call AdStage.init() first.');
54
+ return undefined;
55
+ }
56
+
57
+ return AdStage.events.getUserId();
58
+ }
59
+
60
+ /**
61
+ * 사용자 속성 설정
62
+ * @param properties 사용자 속성 객체
49
63
  *
50
64
  * @example
51
- * setUserId('user123');
65
+ * setUserProperties({
66
+ * gender: 'male',
67
+ * country: 'KR',
68
+ * age: '25'
69
+ * });
52
70
  */
53
- export function setUserId(userId: string): void {
71
+ export function setUserProperties(properties: import('../types/events').UserProperties): void {
54
72
  if (!AdStage.isReady()) {
55
73
  console.warn('AdStage not initialized. Call AdStage.init() first.');
56
74
  return;
57
75
  }
58
76
 
59
- AdStage.events.setUserId(userId);
77
+ AdStage.events.setUserProperties(properties);
60
78
  }
61
79
 
62
80
  /**
63
- * 현재 사용자 ID 반환
81
+ * 현재 사용자 속성 반환
64
82
  */
65
- export function getUserId(): string | undefined {
83
+ export function getUserProperties(): any {
66
84
  if (!AdStage.isReady()) {
67
85
  console.warn('AdStage not initialized. Call AdStage.init() first.');
68
86
  return undefined;
69
87
  }
70
88
 
71
- return AdStage.events.getUserId();
89
+ return AdStage.events.getUserProperties();
72
90
  }
package/src/index.ts CHANGED
@@ -8,7 +8,7 @@ export { default as AdStage } from './core/adstage';
8
8
  import AdStageCore from './core/adstage';
9
9
 
10
10
  // 전역 이벤트 함수들 (Firebase 스타일)
11
- export { track, pageView, setUserId, getUserId } from './events/global-events';
11
+ export { track, setUserId, getUserId, setUserProperties, getUserProperties } from './events/global-events';
12
12
 
13
13
  // React 통합
14
14
  export { AdStageProvider, useAdStageContext, useAdStageInstance } from './react';
@@ -18,7 +18,7 @@ export type { AdStageConfig, ModuleName, BaseModule, ApiResponse, OrganizationIn
18
18
 
19
19
  // 모듈별 타입
20
20
  export type { AdOptions } from './modules/ads/ads-module';
21
- export type { EventProperties, PageData } from './modules/events/events-module';
21
+ export type { EventProperties, UserProperties } from './modules/events/events-module';
22
22
 
23
23
  // 광고 관련 타입
24
24
  export type { AdType, AdEventType, Advertisement, AdSlot } from './types/advertisement';
@@ -6,12 +6,19 @@
6
6
 
7
7
  import { DOMUtils } from '../../utils/dom-utils';
8
8
  import { DeviceInfoCollector } from '../device-info-collector';
9
- import { getSDKVersion } from '../../utils/version';
10
9
  import { ConfigUtils } from '../../utils/config-utils';
11
10
 
12
11
  export class EventDeviceCollector {
12
+ private static _userProvidedDeviceInfo: Partial<{
13
+ category: 'mobile' | 'desktop' | 'tablet' | 'other';
14
+ platform: string;
15
+ model: string;
16
+ appVersion: string;
17
+ osVersion: string;
18
+ }> = {};
13
19
  /**
14
- * Events API용 디바이스 정보 반환
20
+ * Events API용 디바이스 정보 반환 (하이브리드 방식)
21
+ * 사용자 제공 정보 + 자동 수집 정보 병합
15
22
  * TrackEventDto.DeviceInfoInput 형태에 맞춤
16
23
  */
17
24
  static getDeviceInfo(): {
@@ -20,13 +27,33 @@ export class EventDeviceCollector {
20
27
  model?: string;
21
28
  appVersion?: string;
22
29
  osVersion?: string;
30
+ } {
31
+ // 자동 수집된 기본 정보 가져오기
32
+ const autoDetectedInfo = EventDeviceCollector.getAutoDetectedDeviceInfo();
33
+
34
+ // 사용자 제공 정보와 병합 (사용자 정보가 우선)
35
+ return {
36
+ ...autoDetectedInfo,
37
+ ...EventDeviceCollector._userProvidedDeviceInfo
38
+ };
39
+ }
40
+
41
+ /**
42
+ * 자동 감지된 디바이스 정보만 반환
43
+ */
44
+ private static getAutoDetectedDeviceInfo(): {
45
+ category: 'mobile' | 'desktop' | 'tablet' | 'other';
46
+ platform?: string;
47
+ model?: string;
48
+ appVersion?: string;
49
+ osVersion?: string;
23
50
  } {
24
51
  if (!DOMUtils.isBrowser()) {
25
52
  return {
26
53
  category: 'other',
27
54
  platform: 'SSR',
28
55
  model: 'SSR',
29
- appVersion: ConfigUtils.getAppVersion(), // AdStage.init()에서 설정 또는 기본값 '1.0.0'
56
+ appVersion: ConfigUtils.getAppVersion(),
30
57
  osVersion: 'SSR'
31
58
  };
32
59
  }
@@ -49,21 +76,58 @@ export class EventDeviceCollector {
49
76
  category,
50
77
  platform: platformString,
51
78
  model: navigator.platform,
52
- appVersion: ConfigUtils.getAppVersion(), // AdStage.init()에서 설정 또는 기본값 '1.0.0'
79
+ appVersion: ConfigUtils.getAppVersion(),
53
80
  osVersion: navigator.platform
54
81
  };
55
82
  }
56
83
 
84
+ /**
85
+ * 디바이스 정보 설정 (런타임 업데이트)
86
+ */
87
+ static setDeviceInfo(deviceInfo: Partial<{
88
+ category: 'mobile' | 'desktop' | 'tablet' | 'other';
89
+ platform: string;
90
+ model: string;
91
+ appVersion: string;
92
+ osVersion: string;
93
+ }>): void {
94
+ EventDeviceCollector._userProvidedDeviceInfo = {
95
+ ...EventDeviceCollector._userProvidedDeviceInfo,
96
+ ...deviceInfo
97
+ };
98
+ }
99
+
100
+ /**
101
+ * 개별 디바이스 속성 설정
102
+ */
103
+ static setDeviceProperty(key: 'category' | 'platform' | 'model' | 'appVersion' | 'osVersion', value: string): void {
104
+ EventDeviceCollector._userProvidedDeviceInfo[key] = value as any;
105
+ }
106
+
107
+ /**
108
+ * 사용자 제공 디바이스 정보 초기화
109
+ */
110
+ static clearUserProvidedDeviceInfo(): void {
111
+ EventDeviceCollector._userProvidedDeviceInfo = {};
112
+ }
113
+
114
+ /**
115
+ * 현재 사용자가 설정한 디바이스 정보 반환
116
+ */
117
+ static getUserProvidedDeviceInfo(): typeof EventDeviceCollector._userProvidedDeviceInfo {
118
+ return { ...EventDeviceCollector._userProvidedDeviceInfo };
119
+ }
120
+
57
121
  /**
58
122
  * 플랫폼 타입을 Events API용 문자열로 매핑
59
123
  */
60
124
  private static mapPlatformForEvents(platformType: 'ios' | 'android' | 'web' | 'desktop'): string {
61
125
  switch (platformType) {
62
- case 'ios': return 'ios';
63
- case 'android': return 'android';
64
- case 'web': return 'mobile-web';
65
- case 'desktop': return 'desktop-web';
66
- default: return 'unknown';
126
+ case 'ios': return 'iOS';
127
+ case 'android': return 'Android';
128
+ case 'web': return 'Mobile Web';
129
+ case 'desktop': return 'Desktop Web';
130
+ default: return 'Unknown';
67
131
  }
68
132
  }
69
133
 
@@ -10,17 +10,9 @@ import { getSDKVersion } from '../../utils/version';
10
10
  import { EventDeviceCollector } from '../../managers/events/event-device-collector';
11
11
  import { EventUserCollector } from '../../managers/events/event-user-collector';
12
12
  import { EventSessionManager } from '../../managers/events/event-session-manager';
13
+ import type { UserProperties, EventProperties } from '../../types/events';
13
14
 
14
- export interface EventProperties {
15
- [key: string]: any;
16
- }
17
-
18
- export interface PageData {
19
- page?: string;
20
- title?: string;
21
- category?: string;
22
- [key: string]: any;
23
- }
15
+ export type { EventProperties, UserProperties };
24
16
 
25
17
  export class EventsModule implements BaseModule {
26
18
  private _isReady = false;
@@ -73,14 +65,7 @@ export class EventsModule implements BaseModule {
73
65
  /**
74
66
  * 사용자 속성 설정
75
67
  */
76
- setUserProperties(properties: {
77
- gender?: 'male' | 'female' | 'other' | 'unknown';
78
- country?: string;
79
- city?: string;
80
- age?: string;
81
- language?: string;
82
- [key: string]: any;
83
- }): void {
68
+ setUserProperties(properties: UserProperties): void {
84
69
  EventUserCollector.setUserProperties(properties);
85
70
 
86
71
  if (this._config?.debug) {
@@ -136,35 +121,7 @@ export class EventsModule implements BaseModule {
136
121
  }
137
122
  }
138
123
 
139
- /**
140
- * 페이지 뷰 이벤트 (track의 편의 메소드)
141
- */
142
- async pageView(pageData?: PageData): Promise<void> {
143
- const properties: EventProperties = {};
144
-
145
- if (pageData?.page) properties.page = pageData.page;
146
- if (pageData?.title) properties.title = pageData.title;
147
- if (pageData?.category) properties.category = pageData.category;
148
-
149
- // pageData의 다른 속성들도 포함
150
- if (pageData) {
151
- Object.keys(pageData).forEach(key => {
152
- if (key !== 'page' && key !== 'title' && key !== 'category') {
153
- properties[key] = pageData[key];
154
- }
155
- });
156
- }
157
-
158
- // 현재 페이지 정보 자동 수집
159
- if (typeof window !== 'undefined') {
160
- if (!properties.page) properties.page = window.location.pathname;
161
- if (!properties.title) properties.title = document.title;
162
- properties.url = window.location.href;
163
- properties.referrer = document.referrer;
164
- }
165
124
 
166
- await this.track('page_view', properties);
167
- }
168
125
 
169
126
  /**
170
127
  * 서버에 이벤트 전송
@@ -58,3 +58,28 @@ export interface SDKError extends Error {
58
58
  }
59
59
 
60
60
  import type { AdEvent } from './advertisement';
61
+
62
+ /**
63
+ * 사용자 속성 타입
64
+ * API의 UserAttributesInput과 동일한 구조
65
+ */
66
+ export interface UserProperties {
67
+ /** 성별 */
68
+ gender?: 'male' | 'female' | 'other' | 'unknown';
69
+ /** 국가 코드 (ISO 3166-1 alpha-2) */
70
+ country?: string;
71
+ /** 도시명 */
72
+ city?: string;
73
+ /** 나이 (문자열) */
74
+ age?: string;
75
+ /** 언어 코드 (ISO 639-1) */
76
+ language?: string;
77
+ }
78
+
79
+ /**
80
+ * 이벤트 속성 타입
81
+ */
82
+ export interface EventProperties {
83
+ /** 이벤트 매개변수 */
84
+ [key: string]: any;
85
+ }