-
Notifications
You must be signed in to change notification settings - Fork 70
/
actions.js
198 lines (185 loc) · 4.91 KB
/
actions.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import { __ } from '@wordpress/i18n';
import { NAMESPACE, ACTION_PREFIX } from './constants';
import {
trackListProducts,
trackAddToCart,
trackChangeCartItemQuantity,
trackRemoveCartItem,
trackCheckoutStep,
trackCheckoutOption,
trackEvent,
trackSelectContent,
trackSearch,
trackViewItem,
trackException,
} from './tracking';
import { addUniqueAction } from './utils';
/**
* Track customer progress through steps of the checkout. Triggers the event when the step changes:
* 1 - Contact information
* 2 - Shipping address
* 3 - Billing address
* 4 - Shipping options
* 5 - Payment options
*
* @summary Track checkout progress with begin_checkout and checkout_progress
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#1_measure_checkout_steps
*/
addUniqueAction(
`${ ACTION_PREFIX }-checkout-render-checkout-form`,
NAMESPACE,
( { ...storeCart } ) => trackCheckoutStep( 0 )( storeCart )
);
addUniqueAction(
`${ ACTION_PREFIX }-checkout-set-email-address`,
NAMESPACE,
( { ...storeCart } ) => trackCheckoutStep( 1 )( storeCart )
);
addUniqueAction(
`${ ACTION_PREFIX }-checkout-set-shipping-address`,
NAMESPACE,
( { ...storeCart } ) => trackCheckoutStep( 2 )( storeCart )
);
addUniqueAction(
`${ ACTION_PREFIX }-checkout-set-billing-address`,
NAMESPACE,
( { ...storeCart } ) => trackCheckoutStep( 3 )( storeCart )
);
addUniqueAction(
`${ ACTION_PREFIX }-checkout-set-phone-number`,
NAMESPACE,
( { step, ...storeCart } ) => {
trackCheckoutStep( step === 'shipping' ? 2 : 3 )( storeCart );
}
);
/**
* Choose a shipping rate
*
* @summary Track the shipping rate being set using set_checkout_option
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#2_measure_checkout_options
*/
addUniqueAction(
`${ ACTION_PREFIX }-checkout-set-selected-shipping-rate`,
NAMESPACE,
( { shippingRateId } ) => {
trackCheckoutOption( {
step: 4,
option: __( 'Shipping Method', 'woo-gutenberg-products-block' ),
value: shippingRateId,
} )();
}
);
/**
* Choose a payment method
*
* @summary Track the payment method being set using set_checkout_option
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#2_measure_checkout_options
*/
addUniqueAction(
`${ ACTION_PREFIX }-checkout-set-active-payment-method`,
NAMESPACE,
( { paymentMethodSlug } ) => {
trackCheckoutOption( {
step: 5,
option: __( 'Payment Method', 'woo-gutenberg-products-block' ),
value: paymentMethodSlug,
} )();
}
);
/**
* Product List View
*
* @summary Track the view_item_list event
* @see https://developers.google.com/gtagjs/reference/ga4-events#view_item_list
*/
addUniqueAction(
`${ ACTION_PREFIX }-product-list-render`,
NAMESPACE,
trackListProducts
);
/**
* Add to cart.
*
* This event signifies that an item was added to a cart for purchase.
*
* @summary Track the add_to_cart event
* @see https://developers.google.com/gtagjs/reference/ga4-events#add_to_cart
*/
addUniqueAction(
`${ ACTION_PREFIX }-cart-add-item`,
NAMESPACE,
trackAddToCart
);
/**
* Change cart item quantities
*
* @summary Custom change_cart_quantity event.
*/
addUniqueAction(
`${ ACTION_PREFIX }-cart-set-item-quantity`,
NAMESPACE,
trackChangeCartItemQuantity
);
/**
* Remove item from the cart
*
* @summary Track the remove_from_cart event
* @see https://developers.google.com/gtagjs/reference/ga4-events#remove_from_cart
*/
addUniqueAction(
`${ ACTION_PREFIX }-cart-remove-item`,
NAMESPACE,
trackRemoveCartItem
);
/**
* Add Payment Information
*
* This event signifies a user has submitted their payment information. Note, this is used to indicate checkout
* submission, not `purchase` which is triggered on the thanks page.
*
* @summary Track the add_payment_info event
* @see https://developers.google.com/gtagjs/reference/ga4-events#add_payment_info
*/
addUniqueAction( `${ ACTION_PREFIX }-checkout-submit`, NAMESPACE, () => {
trackEvent( 'add_payment_info' );
} );
/**
* Product View Link Clicked
*
* @summary Track the select_content event
* @see https://developers.google.com/gtagjs/reference/ga4-events#select_content
*/
addUniqueAction(
`${ ACTION_PREFIX }-product-view-link`,
NAMESPACE,
trackSelectContent
);
/**
* Product Search
*
* @summary Track the search event
* @see https://developers.google.com/gtagjs/reference/ga4-events#search
*/
addUniqueAction( `${ ACTION_PREFIX }-product-search`, NAMESPACE, trackSearch );
/**
* Single Product View
*
* @summary Track the view_item event
* @see https://developers.google.com/gtagjs/reference/ga4-events#view_item
*/
addUniqueAction(
`${ ACTION_PREFIX }-product-render`,
NAMESPACE,
trackViewItem
);
/**
* Track notices as Exception events.
*
* @summary Track the exception event
* @see https://developers.google.com/analytics/devguides/collection/gtagjs/exceptions
*/
addUniqueAction(
`${ ACTION_PREFIX }-store-notice-create`,
NAMESPACE,
trackException
);