-
Notifications
You must be signed in to change notification settings - Fork 1
/
analytics.js
181 lines (173 loc) · 5.44 KB
/
analytics.js
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
// Example data at the bottom 👇🏼👇🏼👇🏼
/*===================================================================//
VERSION 8 (current)
//===================================================================*/
import firebase, { analytics } from "./init-firebase";
// Log an event
const logAnalyticsEvent = (logEvent, type, id) => {
analytics.logEvent(logEvent, {
content_type: type,
content_id: id,
});
};
// Set user properties
analytics.setUserProperties({ favorite_food: "apples" });
// Events
const eventName = firebase.analytics.EventName;
analytics.logEvent(eventName.VIEW_ITEM_LIST, params1); // Viewed item
analytics.logEvent(eventName.SELECT_ITEM, params2); // Selected item
analytics.logEvent(eventName.VIEW_ITEM, params3); // Viewed product details
analytics.logEvent(eventName.ADD_TO_WISHLIST, params4); // Added to a wishlist
analytics.logEvent(eventName.ADD_TO_CART, params4); // Added to the cart
analytics.logEvent(eventName.VIEW_CART, params5); // Viewed the cart
analytics.logEvent(eventName.REMOVE_FROM_CART, params6); // Removed an item from the cart
analytics.logEvent(eventName.BEGIN_CHECKOUT, params7); // Initiated checkout process
analytics.logEvent(eventName.ADD_SHIPPING_INFO, params8); // Added shipping info
analytics.logEvent(eventName.ADD_PAYMENT_INFO, params9); // Added payment info
analytics.logEvent(eventName.PURCHASE, params10); // Made purchase
analytics.logEvent(eventName.REFUND, params11); // Issued refund
analytics.logEvent(eventName.VIEW_PROMOTION, params12); // Promotion viewed
analytics.logEvent(eventName.SELECT_PROMOTION, params12); // Promotion selected
/*===================================================================//
VERSION 9 (beta)
//===================================================================*/
import { analytics } from "./init-firebase";
import { logEvent, setUserProperties } from "firebase/analytics";
// Log an event
const logAnalyticsEvent = (logEvent, type, id, name) => {
logEvent(analytics, logEvent, {
content_type: type,
content_id: id,
items: [{ name: name }],
});
};
// Set user properties
setUserProperties(analytics, { favorite_food: "apples" });
// Log events
logEvent(analytics, "view_item_list", params1); // Viewed item
logEvent(analytics, "select_item", params2); // Selected item
logEvent(analytics, "view_item", params3); // Viewed product details
logEvent(analytics, "add_to_wishlist", params4); // Added to a wishlist
logEvent(analytics, "add_to_cart", params4); // Added to the cart
logEvent(analytics, "view_cart", params5); // Viewed the cart
logEvent(analytics, "remove_from_cart", params6); // Removed an item from the cart
logEvent(analytics, "begin_checkout", params7); // Initiated checkout process
logEvent(analytics, "add_shipping_info", params8); // Added shipping info
logEvent(analytics, "add_payment_info", params9); // Added payment info
logEvent(analytics, "purchase", params10); // Made purchase
logEvent(analytics, "refund", params11); // Issued refund
logEvent(analytics, "view_promotion", params12); // Promotion viewed
logEvent(analytics, "select_promotion", params12); // Promotion selected
/*===================================================================//
Example data
//===================================================================*/
// Items
const item_jeggings = {
item_id: "SKU_123",
item_name: "jeggings",
item_category: "pants",
item_variant: "black",
item_brand: "Google",
price: 9.99,
};
const item_boots = {
item_id: "SKU_456",
item_name: "boots",
item_category: "shoes",
item_variant: "brown",
item_brand: "Google",
price: 24.99,
};
const item_socks = {
item_id: "SKU_789",
item_name: "ankle_socks",
item_category: "socks",
item_variant: "red",
item_brand: "Google",
price: 5.99,
};
// Params
const params1 = {
item_list_id: "L001",
item_list_name: "Related products",
items: [item_jeggings, item_boots, item_socks],
};
const params2 = {
item_list_id: "L001",
item_list_name: "Related products",
items: [item_jeggings],
};
const params3 = {
currency: "USD",
value: 9.99,
items: [item_jeggings],
};
const params4 = {
currency: "USD",
value: 19.98,
items: [item_jeggings_quantity],
};
const params5 = {
currency: "USD",
value: 44.97,
items: [item_jeggings_quantity, item_boots_quantity],
};
const params6 = {
currency: "USD",
value: 24.99,
items: [item_jeggings],
};
const params7 = {
currency: "USD",
value: 14.98, // Total Revenue
coupon: "SUMMER_FUN",
items: [item_jeggings],
};
const params8 = {
currency: "USD",
value: 14.98, // Total Revenue
coupon: "SUMMER_FUN",
shipping_tier: "Ground",
items: [item_jeggings],
};
const params9 = {
currency: "USD",
value: 14.98, // Total Revenue
coupon: "SUMMER_FUN",
payment_type: "Visa",
items: [item_jeggings],
};
const params10 = {
transaction_id: "T12345",
affiliation: "Google Store",
currency: "USD",
value: 14.98, // Total Revenue
tax: 2.85,
shipping: 5.34,
coupon: "SUMMER_FUN",
items: [item_jeggings],
};
const params11 = {
transaction_id: "T12345", // Required
affiliation: "Google Store",
currency: "USD",
value: 9.99,
items: [],
};
const params12 = {
promotion_id: "ABC123",
promotion_name: "Summer Sale",
creative_name: "summer2020_promo.jpg",
creative_slot: "featured_app_1",
location_id: "HERO_BANNER",
items: [item_jeggings],
};
// Order quantities
const item_jeggings_quantity = {
...item_jeggings,
quantity: 2,
};
const item_boots_quantity = {
...item_boots,
quantity: 1,
};