@rakutenanalytics/rat-ts 0.6.2-rc.c84a2bd
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.md +322 -0
- package/dist/index.js +1818 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/internal/ralConfig.d.ts +25 -0
- package/dist/lib/tracker.d.ts +191 -0
- package/dist/lib/types/config.d.ts +11 -0
- package/dist/lib/types/core.d.ts +5 -0
- package/dist/lib/types/events.d.ts +151 -0
- package/dist/lib/types/genericParams.d.ts +778 -0
- package/dist/lib/types/index.d.ts +7 -0
- package/dist/lib/types/tracker.d.ts +97 -0
- package/dist/lib/utils.d.ts +3 -0
- package/package.json +27 -0
package/README.md
ADDED
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
# Rakuten Analytics TypeScript SDK
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for Rakuten Analytics Tracking, providing type-safe analytics integration for web applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install latest production version
|
|
9
|
+
npm install @rakutenanalytics/rat-ts
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
### Basic Usage
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { Tracker } from '@rakutenanalytics/rat-ts';
|
|
18
|
+
|
|
19
|
+
// Initialize tracker
|
|
20
|
+
const tracker = new Tracker({
|
|
21
|
+
accountId: 999,
|
|
22
|
+
serviceId: 1
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Track a page view
|
|
26
|
+
tracker.sendPageviewEvent({
|
|
27
|
+
params: {
|
|
28
|
+
pageName: 'home'
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Track a click event
|
|
33
|
+
tracker.sendClickEvent({
|
|
34
|
+
params: {
|
|
35
|
+
itemId: ['product123', 'category456']
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Advanced Configuration
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { Tracker, TransportMethod, ReceiverEndpoint } from '@rakutenanalytics/rat-ts';
|
|
44
|
+
|
|
45
|
+
const tracker = new Tracker({
|
|
46
|
+
accountId: 999,
|
|
47
|
+
serviceId: 1,
|
|
48
|
+
mainReceiver: ReceiverEndpoint.JP_SEC,
|
|
49
|
+
transportMethod: TransportMethod.BEACON
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## API Reference
|
|
54
|
+
|
|
55
|
+
### Tracker Class
|
|
56
|
+
|
|
57
|
+
#### Constructor Options
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
interface TrackerOptions {
|
|
61
|
+
accountId: number; // Required: Your Rakuten Analytics account ID
|
|
62
|
+
serviceId: number; // Required: Your service ID
|
|
63
|
+
mainReceiver?: ReceiverEndpoint; // Optional: Analytics endpoint
|
|
64
|
+
transportMethod?: TransportMethod; // Optional: Data transport method
|
|
65
|
+
customCookies?: Record<string, string>; // Optional: Custom cookie values
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### Methods
|
|
70
|
+
|
|
71
|
+
##### `sendPageviewEvent(params: PageviewParams): void`
|
|
72
|
+
|
|
73
|
+
Send a page view event.
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
tracker.sendPageviewEvent({
|
|
77
|
+
params?: InputGenericParams, // Standard analytics parameters
|
|
78
|
+
customParams?: CustomParams, // Custom parameters for advanced use cases
|
|
79
|
+
cvEvents?: ConversionEvents // Conversion tracking events
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
##### `sendClickEvent(params: ClickEventParams): void`
|
|
84
|
+
|
|
85
|
+
Send a click event.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
tracker.sendClickEvent({
|
|
89
|
+
params?: InputGenericParams, // Standard analytics parameters
|
|
90
|
+
customParams?: CustomParams, // Custom parameters for advanced use cases
|
|
91
|
+
cvEvents?: ConversionEvents // Conversion tracking events
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
##### `sendEvent(event: Event): void`
|
|
96
|
+
|
|
97
|
+
Send a generic analytics event with the specified type and parameters (for advanced use cases).
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
tracker.sendEvent({
|
|
101
|
+
type: 'appear', // Event type: 'pv', 'click', 'appear', 'async', 'scroll'
|
|
102
|
+
params?: InputGenericParams, // Standard analytics parameters
|
|
103
|
+
customParams?: CustomParams, // Custom parameters for advanced use cases
|
|
104
|
+
cvEvents?: ConversionEvents // Conversion tracking events
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Event Types
|
|
109
|
+
|
|
110
|
+
#### Page View Event
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
tracker.sendPageviewEvent({
|
|
114
|
+
params: {
|
|
115
|
+
pageName: 'product-detail',
|
|
116
|
+
itemId: ['product123'],
|
|
117
|
+
genre: ['electronics', 'smartphones']
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### Click Event
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
tracker.sendClickEvent({
|
|
126
|
+
params: {
|
|
127
|
+
itemId: ['product123', 'product456'],
|
|
128
|
+
pageName: 'search-results'
|
|
129
|
+
},
|
|
130
|
+
customParams: {
|
|
131
|
+
clktgt: 'product-image',
|
|
132
|
+
totalresults: 150
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
#### Conversion Event
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
tracker.sendPageviewEvent({
|
|
141
|
+
cvEvents: {
|
|
142
|
+
'purchase_gms': 3400, // Purchase amount
|
|
143
|
+
'purchase_order': 1, // Number of orders
|
|
144
|
+
'purchase_shop': 2 // Number of shops
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### Custom Event with Advanced Parameters
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
tracker.sendEvent({
|
|
153
|
+
type: 'async',
|
|
154
|
+
params: {
|
|
155
|
+
pageName: 'checkout',
|
|
156
|
+
itemId: ['item1', 'item2'],
|
|
157
|
+
genre: ['books', 'electronics'],
|
|
158
|
+
price: [1200, 3400]
|
|
159
|
+
},
|
|
160
|
+
customParams: {
|
|
161
|
+
hits: 5,
|
|
162
|
+
rpgn: 2,
|
|
163
|
+
sort: 1,
|
|
164
|
+
notification: 3
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Configuration Enums
|
|
170
|
+
|
|
171
|
+
#### TransportMethod
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
enum TransportMethod {
|
|
175
|
+
XHR = 'xhr', // XMLHttpRequest (default)
|
|
176
|
+
BEACON = 'beacon' // Navigator.sendBeacon (recommended for page unload)
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
#### ReceiverEndpoint
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
enum ReceiverEndpoint {
|
|
184
|
+
JP = "rat.rakuten.co.jp",
|
|
185
|
+
JP_SEC = "secure.rat.rakuten.co.jp",
|
|
186
|
+
FR = "rat.rakuten.fr",
|
|
187
|
+
DE = "rat.rakuten.de",
|
|
188
|
+
ES = "rat.rakuten.es",
|
|
189
|
+
UK = "rat.rakuten.co.uk",
|
|
190
|
+
STG_JP = "stg.rat.rakuten.co.jp",
|
|
191
|
+
STG_JP_SEC = "stg.secure.rat.rakuten.co.jp",
|
|
192
|
+
CHECK_JP = "check.rat.rakuten.co.jp",
|
|
193
|
+
CHECK_JP_SEC = "check.secure.rat.rakuten.co.jp"
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Common Use Cases
|
|
198
|
+
|
|
199
|
+
### E-commerce Product Tracking
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// Product page view
|
|
203
|
+
tracker.sendPageviewEvent({
|
|
204
|
+
params: {
|
|
205
|
+
pageName: 'item',
|
|
206
|
+
itemId: ['123456'],
|
|
207
|
+
genre: ['electronics', 'smartphones'],
|
|
208
|
+
price: [29800]
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
// Add to cart click
|
|
213
|
+
tracker.sendClickEvent({
|
|
214
|
+
params: {
|
|
215
|
+
itemId: ['123456']
|
|
216
|
+
},
|
|
217
|
+
customParams: {
|
|
218
|
+
clktgt: 'add-to-cart'
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// Purchase conversion
|
|
223
|
+
tracker.sendPageviewEvent({
|
|
224
|
+
params: {
|
|
225
|
+
pageName: 'purchase-complete'
|
|
226
|
+
},
|
|
227
|
+
cvEvents: {
|
|
228
|
+
'purchase_gms': 29800,
|
|
229
|
+
'purchase_order': 1,
|
|
230
|
+
'purchase_item': 1
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Search Results Tracking
|
|
236
|
+
|
|
237
|
+
```typescript
|
|
238
|
+
tracker.sendPageviewEvent({
|
|
239
|
+
params: {
|
|
240
|
+
pageName: 'search',
|
|
241
|
+
searchQuery: 'smartphone iPhone'
|
|
242
|
+
},
|
|
243
|
+
customParams: {
|
|
244
|
+
hits: 247,
|
|
245
|
+
rpgn: 1,
|
|
246
|
+
totalresults: 247,
|
|
247
|
+
sort: 1
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### Content Visibility Tracking
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
// Track when content becomes visible
|
|
256
|
+
tracker.sendEvent({
|
|
257
|
+
type: 'appear',
|
|
258
|
+
params: {
|
|
259
|
+
page: 'article',
|
|
260
|
+
itemid: ['article123']
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// Track scroll events
|
|
265
|
+
tracker.sendEvent({
|
|
266
|
+
type: 'scroll',
|
|
267
|
+
params: {
|
|
268
|
+
page: 'article'
|
|
269
|
+
},
|
|
270
|
+
customParams: {
|
|
271
|
+
scrollDepth: 75
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
## TypeScript Integration
|
|
277
|
+
|
|
278
|
+
### Type Definitions
|
|
279
|
+
|
|
280
|
+
The SDK provides comprehensive TypeScript definitions for all parameters:
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
import type {
|
|
284
|
+
TrackerOptions,
|
|
285
|
+
Event,
|
|
286
|
+
InputGenericParams,
|
|
287
|
+
ConversionEvents,
|
|
288
|
+
CustomParams
|
|
289
|
+
} from '@rakutenanalytics/rat-ts';
|
|
290
|
+
|
|
291
|
+
// Type-safe event creation
|
|
292
|
+
const pageviewParams: PageviewParams = {
|
|
293
|
+
params: {
|
|
294
|
+
pageName: 'home',
|
|
295
|
+
itemId: ['123'],
|
|
296
|
+
// TypeScript will provide autocomplete and validation
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
### Enum Usage
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
import {
|
|
305
|
+
PglEnum,
|
|
306
|
+
PgtEnum,
|
|
307
|
+
TransportMethod,
|
|
308
|
+
ReceiverEndpoint
|
|
309
|
+
} from '@rakutenanalytics/rat-ts';
|
|
310
|
+
|
|
311
|
+
// Use enums for type safety
|
|
312
|
+
tracker.sendPageviewEvent({
|
|
313
|
+
params: {
|
|
314
|
+
pageLayout: PglEnum.PC,
|
|
315
|
+
pageType: PgtEnum.TOP
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## Support
|
|
321
|
+
|
|
322
|
+
For questions, bug reports, or feature requests, please contact the Rakuten Analytics team.
|