/
types.ts
181 lines (170 loc) · 4.2 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { Package, Action } from "frontity/types";
import Source from "@frontity/source/types";
import Router from "@frontity/router/types";
/**
* Pageview payload passed to analytics `pageview` actions.
*/
export interface Pageview {
/**
* Link of the page (without the host part).
*
* @example "/2016/the-beauties-of-gullfoss"
*/
link: string;
/**
* Title of the page.
*
* @example "The Beauties Of Gullfoss - Frontity Test"
*/
title: string;
}
/**
* Eventy payload passed to analytics `event` actions.
*/
export interface Event {
/**
* The name of the event.
*
* @example "Click"
*/
name: string;
/**
* Collection of properties sent along with the event.
*
* @remarks
* Each analytics package requires some specific properties to be included
* here. Check out their documentation for more info.
*
* @example
* ```
* {
* label: "video",
* category: "youtube",
* }
* ```
*/
payload: Record<string, any>;
}
/**
* Base types and actions to build analytics packages for Frontity.
*/
interface Analytics extends Package {
/**
* Root elements exposed by this package.
*/
roots: {
/**
* Analytics root element.
*/
analytics: React.FC;
};
/**
* The actions exposed by this package.
*/
actions: {
/**
* Analytics namespace.
*/
analytics: {
/**
* Send a pageview to all active analytics packages.
*
* This action takes all namespaces defined in `state.analytics.pageviews`
* that are `true` and calls the `pageview` action of each one with the
* specified `Pageview` object.
*
* @remarks
* This action is used by the `roots.analytics` component and is not
* meant to be called directly.
*
* @example
* ```
* actions.analytics.pageview({
* link: "/2016/the-beauties-of-gullfoss",
* title: "The Beauties Of Gullfoss",
* });
* ```
*
* @param pageview - Object of type {@link Pageview}.
*/
pageview: Action<Analytics, Pageview>;
/**
* Send an event to all active analytics packages.
*
* This action takes all namespaces defined in `state.analytics.events`
* that are `true` and calls the `event` action of each one with the
* specified `Event` object.
*
* @example
* ```
* actions.analytics.event({
* name: "click",
* payload: {
* category: "video",
* label: "featured-media",
* },
* });
* ```
*
* @param event - Object of type {@link Event}.
*/
event: Action<Analytics, Event>;
};
};
/**
* The state exposed by this package.
*/
state: {
/**
* Analytics namespace.
*/
analytics: {
/**
* Map of namespaces with boolean values.
*
* This object is used by `actions.analytics.pageview` to know which
* analytics packages should send the pageview to their respective
* services.
*
* @remarks
* If you want to disable sending pageviews for a specific analytics
* package, the respective namespace of that package should be set here to
* `false`.
*
* @example
* ```
* pageviews: {
* googleAnalytics: false,
* comscoreAnalytics: true
* }
* ```
*/
pageviews: Record<string, boolean>;
/**
* Map of namespaces with boolean values.
*
* This object is used by `actions.analytics.event` to know which
* analytics packages should send the event to their respective services.
*
* @remarks
* If you want to disable sending events for a specific analytics
* package, the respective namespace of that package should be set here to
* `false`.
*
* @example
* ```
* events: {
* googleAnalytics: true,
* comscoreAnalytics: false,
* }
* ```
*/
events: Record<string, boolean>;
};
};
}
/**
* Package types used internally by Analytics.
*/
export type Packages = Analytics & Router & Source;
export default Analytics;