@@ -13,7 +13,7 @@ type CreateEventInput = {
13
13
@Injectable ( )
14
14
export class AnalyticsService {
15
15
private readonly logger = new Logger ( AnalyticsService . name ) ;
16
- private readonly datasource = 'event' ;
16
+ private readonly defaultDatasource = 'event' ;
17
17
18
18
constructor (
19
19
private readonly environmentService : EnvironmentService ,
@@ -29,16 +29,31 @@ export class AnalyticsService {
29
29
return { success : true } ;
30
30
}
31
31
32
- const data = {
33
- action : createEventInput . action ,
34
- timestamp : new Date ( ) . toISOString ( ) ,
35
- version : '1' ,
36
- payload : {
37
- userId : userId ,
38
- workspaceId : workspaceId ,
39
- ...createEventInput . payload ,
40
- } ,
41
- } ;
32
+ let data ;
33
+
34
+ switch ( createEventInput . action ) {
35
+ case 'pageview' :
36
+ data = {
37
+ timestamp : new Date ( ) . toISOString ( ) ,
38
+ version : '1' ,
39
+ userId : userId ,
40
+ workspaceId : workspaceId ,
41
+ ...createEventInput . payload ,
42
+ } ;
43
+ break ;
44
+ default :
45
+ data = {
46
+ action : createEventInput . action ,
47
+ timestamp : new Date ( ) . toISOString ( ) ,
48
+ version : '1' ,
49
+ userId : userId ,
50
+ workspaceId : workspaceId ,
51
+ payload : {
52
+ ...createEventInput . payload ,
53
+ } ,
54
+ } ;
55
+ break ;
56
+ }
42
57
43
58
const config : AxiosRequestConfig = {
44
59
headers : {
@@ -47,9 +62,14 @@ export class AnalyticsService {
47
62
} ,
48
63
} ;
49
64
65
+ const datasource =
66
+ createEventInput . action === 'pageview'
67
+ ? 'pageview'
68
+ : this . defaultDatasource ;
69
+
50
70
try {
51
71
await this . httpService . axiosRef . post (
52
- `/events?name=${ this . datasource } ` ,
72
+ `/events?name=${ datasource } ` ,
53
73
data ,
54
74
config ,
55
75
) ;
0 commit comments