@adstage/web-sdk 3.0.1 → 3.0.2
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/README.ko.md +508 -0
- package/README.md +163 -527
- package/dist/index.cjs.js +1 -4714
- package/dist/index.d.ts +42 -35
- package/dist/index.esm.js +1 -4703
- package/dist/index.standalone.js +2 -4767
- package/dist/index.umd.js +3 -4785
- package/package.json +5 -2
- package/src/events/global-events.ts +33 -15
- package/src/index.ts +2 -2
- package/src/modules/events/events-module.ts +3 -46
- package/src/types/events.ts +25 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adstage/web-sdk",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
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
|
|
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
|
|
33
|
+
* 사용자 ID 설정
|
|
34
|
+
* @param userId 사용자 ID
|
|
33
35
|
*
|
|
34
36
|
* @example
|
|
35
|
-
*
|
|
37
|
+
* setUserId('user123');
|
|
36
38
|
*/
|
|
37
|
-
export function
|
|
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
|
|
42
|
+
return;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
|
|
45
|
+
AdStage.events.setUserId(userId);
|
|
44
46
|
}
|
|
45
47
|
|
|
46
48
|
/**
|
|
47
|
-
* 사용자 ID
|
|
48
|
-
|
|
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
|
-
*
|
|
65
|
+
* setUserProperties({
|
|
66
|
+
* gender: 'male',
|
|
67
|
+
* country: 'KR',
|
|
68
|
+
* age: '25'
|
|
69
|
+
* });
|
|
52
70
|
*/
|
|
53
|
-
export function
|
|
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.
|
|
77
|
+
AdStage.events.setUserProperties(properties);
|
|
60
78
|
}
|
|
61
79
|
|
|
62
80
|
/**
|
|
63
|
-
* 현재 사용자
|
|
81
|
+
* 현재 사용자 속성 반환
|
|
64
82
|
*/
|
|
65
|
-
export function
|
|
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.
|
|
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,
|
|
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,
|
|
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';
|
|
@@ -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
|
|
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
|
* 서버에 이벤트 전송
|
package/src/types/events.ts
CHANGED
|
@@ -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
|
+
}
|