@chordcommerce/analytics 1.5.1

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.
@@ -0,0 +1,86 @@
1
+ import type { AnalyticsSnippet, Analytics, AnalyticsBrowser, Options } from '@segment/analytics-next';
2
+ import type { Cart, Checkout, Product, LineItem } from './objects.js';
3
+ import type { CartViewed, CheckoutStarted, CouponApplied, CouponDenied, CouponEntered, CouponRemoved, EmailCaptured, ProductAdded, ProductClicked, ProductListFiltered, ProductListViewed, ProductRemoved, ProductViewed, ProductsSearched, SignedIn, SignedOut, SignedUp } from './typewriter.js';
4
+ import type { CartViewedInput, CheckoutStartedInput, EmailCapturedInput, ProductAddedInput, ProductClickedInput, ProductListFilteredInput, ProductListViewedInput, ProductRemovedInput, ProductViewedInput, ProductsSearchedInput, ProductInput, CartInput, CheckoutInput, LineItemInput, CouponAppliedInput, CouponDeniedInput, CouponEnteredInput, CouponRemovedInput, SignedInInput, SignedOutInput, SignedUpInput } from './input.js';
5
+ export interface ValidateResult {
6
+ success: boolean;
7
+ error?: any[];
8
+ data?: any;
9
+ }
10
+ export type AnyAnalytics = AnalyticsSnippet | Analytics | AnalyticsBrowser;
11
+ export type AnyOptions = Options;
12
+ export type AnyProduct = {
13
+ [key: string]: unknown;
14
+ };
15
+ export type AnyCart = {
16
+ [key: string]: unknown;
17
+ };
18
+ export type AnyCheckout = {
19
+ [key: string]: unknown;
20
+ };
21
+ export type AnyId = string | number;
22
+ export type AnyLineItem = {
23
+ [key: string]: unknown;
24
+ };
25
+ export interface ChordAnalyticsOptions {
26
+ cdp?: AnyAnalytics | (() => AnyAnalytics);
27
+ debug?: boolean;
28
+ enableLogging?: boolean;
29
+ formatters: {
30
+ events?: {
31
+ cartViewed?: (props: CartViewedInput, event: CartViewed) => CartViewed;
32
+ checkoutStarted?: (props: CheckoutStartedInput, event: CheckoutStarted) => CheckoutStarted;
33
+ couponApplied?: (props: CouponAppliedInput, event: CouponApplied) => CouponApplied;
34
+ couponDenied?: (props: CouponDeniedInput, event: CouponDenied) => CouponDenied;
35
+ couponEntered?: (props: CouponEnteredInput, event: CouponEntered) => CouponEntered;
36
+ couponRemoved?: (props: CouponRemovedInput, event: CouponRemoved) => CouponRemoved;
37
+ emailCaptured?: (props: EmailCapturedInput, event: EmailCaptured) => EmailCaptured;
38
+ productAdded?: (props: ProductAddedInput, event: ProductAdded) => ProductAdded;
39
+ productClicked?: (props: ProductClickedInput, event: ProductClicked) => ProductClicked;
40
+ productListFiltered?: (props: ProductListFilteredInput, event: ProductListFiltered) => ProductListFiltered;
41
+ productListViewed?: (props: ProductListViewedInput, event: ProductListViewed) => ProductListViewed;
42
+ productRemoved?: (props: ProductRemovedInput, event: ProductRemoved) => ProductRemoved;
43
+ productViewed?: (props: ProductViewedInput, event: ProductViewed) => ProductViewed;
44
+ productsSearched?: (props: ProductsSearchedInput, event: ProductsSearched) => ProductsSearched;
45
+ signedIn?: (props: SignedInInput, event: SignedIn) => SignedIn;
46
+ signedOut?: (props: SignedOutInput, event: SignedOut) => SignedOut;
47
+ signedUp?: (props: SignedUpInput, event: SignedUp) => SignedUp;
48
+ };
49
+ objects: {
50
+ cart: (props: CartInput) => Cart;
51
+ checkout: (props: CheckoutInput) => Checkout;
52
+ lineItem: (props: LineItemInput) => LineItem;
53
+ product: (props: ProductInput) => Product;
54
+ };
55
+ };
56
+ stripNull?: boolean;
57
+ metadata: EventMetadata;
58
+ }
59
+ export interface EventMetadata {
60
+ i18n: i18nMetadata;
61
+ ownership: ownershipMetadata;
62
+ platform: platformMetadata;
63
+ store: storeMetadata;
64
+ version?: versionMetadata;
65
+ }
66
+ export interface i18nMetadata {
67
+ currency: string;
68
+ locale: string;
69
+ }
70
+ export interface ownershipMetadata {
71
+ omsId: string;
72
+ storeId: string;
73
+ tenantId: string;
74
+ }
75
+ export interface platformMetadata {
76
+ name: string;
77
+ type: string;
78
+ }
79
+ export interface versionMetadata {
80
+ major: number;
81
+ minor: number;
82
+ patch: number;
83
+ }
84
+ export interface storeMetadata {
85
+ domain: string;
86
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export type { AnalyticsSnippet, Analytics, AnalyticsBrowser, EventProperties, Options, } from '@segment/analytics-next';
2
+ export * from './objects.js';
3
+ export * from './typewriter.js';
4
+ export * from './client.js';
5
+ export * from './input.js';
@@ -0,0 +1,4 @@
1
+ export * from './objects.js';
2
+ export * from './typewriter.js';
3
+ export * from './client.js';
4
+ export * from './input.js';
@@ -0,0 +1,223 @@
1
+ import type { AnyCart, AnyCheckout, AnyId, AnyLineItem, AnyProduct } from './client.js';
2
+ import type { Filter, Sort } from './typewriter.js';
3
+ export interface ProductInput {
4
+ /**
5
+ * The position in a list of the product that was added, if relevant.
6
+ */
7
+ position?: number;
8
+ /**
9
+ * Product and variant details, like product name and variant SKUs.
10
+ */
11
+ product: AnyProduct;
12
+ /**
13
+ * The quantity of the product involved in the tracking event. Sometimes quantity might
14
+ * not be relevant to an event, and can be either omitted or defaulted to `1`.
15
+ */
16
+ quantity?: number;
17
+ /**
18
+ * The unique identifier of the product variant. This should allow you to look up the
19
+ * selected variant details from the `product` object. If not provided, it's typical
20
+ * to default to the first product variant, or default product variant if that's a concept
21
+ * that exists in your product catalog.
22
+ */
23
+ variantId?: AnyId;
24
+ }
25
+ export interface CartInput {
26
+ /**
27
+ * The current cart.
28
+ */
29
+ cart: AnyCart;
30
+ }
31
+ export interface CheckoutInput {
32
+ /**
33
+ * The current checkout.
34
+ */
35
+ checkout: AnyCheckout;
36
+ }
37
+ export interface LineItemInput {
38
+ /**
39
+ * The line item before it was removed.
40
+ */
41
+ lineItem: AnyLineItem;
42
+ }
43
+ export interface CartViewedInput {
44
+ /**
45
+ * The current cart.
46
+ */
47
+ cart: AnyCart;
48
+ }
49
+ export interface CheckoutStartedInput {
50
+ /**
51
+ * The current checkout.
52
+ */
53
+ checkout: AnyCheckout;
54
+ }
55
+ /**
56
+ * Coupon was applied on a user's shopping cart or order
57
+ */
58
+ export interface CouponAppliedInput {
59
+ /**
60
+ * Cart ID, if applicable
61
+ */
62
+ cartId?: string;
63
+ /**
64
+ * Coupon ID
65
+ */
66
+ couponId?: string;
67
+ /**
68
+ * Coupon name
69
+ */
70
+ couponName?: string;
71
+ /**
72
+ * Monetary discount applied through the coupon
73
+ */
74
+ discount?: number;
75
+ /**
76
+ * Order/transaction ID, if applicable
77
+ */
78
+ orderId?: string;
79
+ }
80
+ /**
81
+ * Coupon was denied from a user's shopping cart or order
82
+ */
83
+ export interface CouponDeniedInput {
84
+ /**
85
+ * Cart ID, if applicable
86
+ */
87
+ cartId?: string;
88
+ /**
89
+ * Coupon ID
90
+ */
91
+ couponId?: string;
92
+ /**
93
+ * Coupon name
94
+ */
95
+ couponName?: string;
96
+ /**
97
+ * Order/transaction ID, if applicable
98
+ */
99
+ orderId?: string;
100
+ /**
101
+ * Reason the coupon was denied
102
+ */
103
+ reason?: string;
104
+ }
105
+ /**
106
+ * User entered a coupon on a shopping cart or order
107
+ */
108
+ export interface CouponEnteredInput {
109
+ /**
110
+ * Cart ID, if applicable
111
+ */
112
+ cartId?: string;
113
+ /**
114
+ * Coupon ID
115
+ */
116
+ couponId?: string;
117
+ /**
118
+ * Coupon name
119
+ */
120
+ couponName?: string;
121
+ /**
122
+ * Order/transaction ID, if applicable
123
+ */
124
+ orderId?: string;
125
+ }
126
+ /**
127
+ * User removed a coupon from a cart or order
128
+ */
129
+ export interface CouponRemovedInput {
130
+ /**
131
+ * Cart ID, if applicable
132
+ */
133
+ cartId?: string;
134
+ /**
135
+ * Coupon ID
136
+ */
137
+ couponId?: string;
138
+ /**
139
+ * Coupon name
140
+ */
141
+ couponName?: string;
142
+ /**
143
+ * Monetary discount applied through the coupon
144
+ */
145
+ discount?: number;
146
+ /**
147
+ * Order/transaction ID, if applicable
148
+ */
149
+ orderId?: string;
150
+ [property: string]: any;
151
+ }
152
+ export interface EmailCapturedInput {
153
+ email?: string;
154
+ placementComponent?: string;
155
+ placementPage?: string;
156
+ }
157
+ export interface ProductAddedInput {
158
+ /**
159
+ * The current cart, after the product is added.
160
+ */
161
+ cart: AnyCart;
162
+ product: ProductInput;
163
+ }
164
+ export interface ProductClickedInput {
165
+ /**
166
+ * The current cart.
167
+ */
168
+ cart: AnyCart;
169
+ listId?: AnyId;
170
+ listName?: string;
171
+ product: ProductInput;
172
+ }
173
+ export interface ProductListFilteredInput {
174
+ category?: string;
175
+ listId?: string;
176
+ listName?: string;
177
+ filters?: Filter[];
178
+ sorts?: Sort[];
179
+ }
180
+ export interface ProductListViewedInput {
181
+ category?: string;
182
+ listId?: string;
183
+ listName?: string;
184
+ products: ProductInput[];
185
+ }
186
+ export interface ProductRemovedInput {
187
+ /**
188
+ * The current cart.
189
+ */
190
+ cart: AnyCart;
191
+ /**
192
+ * The line item before it was removed.
193
+ */
194
+ lineItem: AnyLineItem;
195
+ }
196
+ export interface ProductViewedInput {
197
+ /**
198
+ * The current cart.
199
+ */
200
+ cart: AnyCart;
201
+ /**
202
+ * The product being viewed.
203
+ */
204
+ product: ProductInput;
205
+ }
206
+ export interface ProductsSearchedInput {
207
+ currency?: string;
208
+ price?: number;
209
+ productId?: AnyId;
210
+ quantity?: number;
211
+ query?: string;
212
+ }
213
+ export interface SignedInInput {
214
+ email?: string;
215
+ method?: string;
216
+ }
217
+ export interface SignedOutInput {
218
+ email?: string;
219
+ }
220
+ export interface SignedUpInput {
221
+ email?: string;
222
+ method?: string;
223
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,379 @@
1
+ export interface Cart {
2
+ /**
3
+ * Cart ID
4
+ */
5
+ cart_id?: string;
6
+ /**
7
+ * Currency code of the transaction (for example, "USD")
8
+ */
9
+ currency?: string;
10
+ /**
11
+ * Products in the cart
12
+ */
13
+ products: LineItem[];
14
+ /**
15
+ * Revenue ($) with discounts and coupons added in
16
+ */
17
+ value?: number;
18
+ }
19
+ export interface IdentifyTraits {
20
+ /**
21
+ * Street address of a user.
22
+ */
23
+ address?: {
24
+ city?: string;
25
+ country?: string;
26
+ postalCode?: string;
27
+ state?: string;
28
+ street?: string;
29
+ [property: string]: any;
30
+ };
31
+ /**
32
+ * Age of a user
33
+ */
34
+ age?: number;
35
+ /**
36
+ * URL to an avatar image for the user
37
+ */
38
+ avatar?: string;
39
+ /**
40
+ * User’s birthday. Segment recommends using ISO-8601 date strings.
41
+ */
42
+ birthday?: string;
43
+ /**
44
+ * Company the user represents
45
+ */
46
+ company?: {
47
+ name?: string;
48
+ id?: string | number;
49
+ industry?: string;
50
+ employeeCount?: number;
51
+ plan?: string;
52
+ [property: string]: any;
53
+ };
54
+ /**
55
+ * Date the user’s account was first created. Segment recommends using ISO-8601 date strings.
56
+ */
57
+ createdAt?: string;
58
+ /**
59
+ * Description of the user
60
+ */
61
+ description?: string;
62
+ /**
63
+ * Email address of a user
64
+ */
65
+ email?: string;
66
+ /**
67
+ * First name of a user
68
+ */
69
+ firstName?: string;
70
+ /**
71
+ * Gender of a user
72
+ */
73
+ gender?: string;
74
+ /**
75
+ * Unique ID in your database for a user
76
+ */
77
+ id?: string;
78
+ /**
79
+ * Last name of a user
80
+ */
81
+ lastName?: string;
82
+ /**
83
+ * Full name of a user. If you only pass a first and last name Segment automatically fills in the full name for you.
84
+ */
85
+ name?: string;
86
+ /**
87
+ * Phone number of a user
88
+ */
89
+ phone?: string;
90
+ /**
91
+ * Title of a user, usually related to their position at a specific company. Example: “VP of Engineering”
92
+ */
93
+ title?: string;
94
+ /**
95
+ * User’s username. This should be unique to each user, like the usernames of Twitter or GitHub.
96
+ */
97
+ username?: string;
98
+ /**
99
+ * Website of a user
100
+ */
101
+ website?: string;
102
+ /**
103
+ * Additional custom user traits.
104
+ */
105
+ [property: string]: any;
106
+ }
107
+ export interface LineItem extends Product {
108
+ /**
109
+ * Coupon code associated with a product (for example, "MAY_DEALS_3")
110
+ */
111
+ coupon?: string;
112
+ /**
113
+ * Database ID of the line item
114
+ */
115
+ line_item_id?: string;
116
+ /**
117
+ * Quantity of the product
118
+ */
119
+ quantity: number;
120
+ }
121
+ export interface Order {
122
+ /**
123
+ * Store or affiliation from which this transaction occurred (for example, "Google Store")
124
+ */
125
+ affiliation?: string;
126
+ /**
127
+ * Order metadata "campaign_id"
128
+ */
129
+ campaign_id?: number;
130
+ /**
131
+ * Channel where order was placed (for example, "chord")
132
+ */
133
+ channel?: string;
134
+ /**
135
+ * Checkout provider (for example, "stripe")
136
+ */
137
+ checkout_type?: string;
138
+ /**
139
+ * Transaction coupon redeemed with the transaction
140
+ */
141
+ coupon?: string;
142
+ /**
143
+ * Currency code of the transaction (for example, "USD")
144
+ */
145
+ currency?: string;
146
+ /**
147
+ * Total discount associated with the transaction
148
+ */
149
+ discount?: number;
150
+ /**
151
+ * Email address associated with the order
152
+ */
153
+ email?: string;
154
+ /**
155
+ * First name in the shipping address for the order
156
+ */
157
+ first_name?: string;
158
+ /**
159
+ * Order contains a subscription
160
+ */
161
+ has_subscription?: boolean;
162
+ /**
163
+ * Order contains a subscription
164
+ */
165
+ is_recurring?: boolean;
166
+ /**
167
+ * Last name in the shipping address for the order
168
+ */
169
+ last_name?: string;
170
+ /**
171
+ * Metadata of the order
172
+ */
173
+ metadata?: {
174
+ [k: string]: unknown;
175
+ };
176
+ /**
177
+ * Date and time order was placed
178
+ */
179
+ order_date?: string;
180
+ /**
181
+ * Order/transaction ID
182
+ */
183
+ order_id?: string;
184
+ /**
185
+ * Phone number associated with the order
186
+ */
187
+ phone?: string;
188
+ /**
189
+ * Products in the order
190
+ */
191
+ products?: (LineItem & {
192
+ /**
193
+ * Number of SKUs in the bundle
194
+ */
195
+ bundle_size?: number;
196
+ /**
197
+ * Quantity sold via cross-selling
198
+ */
199
+ cross_sold_quantity?: number;
200
+ /**
201
+ * Metadata of the product variant
202
+ */
203
+ variant_metadata?: {
204
+ [k: string]: unknown;
205
+ };
206
+ })[];
207
+ /**
208
+ * URL for customer to share to receive referral credit
209
+ */
210
+ purl_link?: string;
211
+ /**
212
+ * ID for referral that customer used to place the order
213
+ */
214
+ referral_identifier_id?: string;
215
+ /**
216
+ * Revenue ($) associated with the transaction (excluding shipping and tax)
217
+ */
218
+ revenue?: number;
219
+ /**
220
+ * Shipping cost associated with the transaction
221
+ */
222
+ shipping?: number;
223
+ /**
224
+ * City in the shipping address for the order
225
+ */
226
+ shipping_city?: string;
227
+ /**
228
+ * Country in the shipping address for the order
229
+ */
230
+ shipping_country?: string;
231
+ shipping_method_details?: {
232
+ /**
233
+ * Code of shipping method chosen for the order (for example, "standard_shipping")
234
+ */
235
+ shipping_code?: string;
236
+ /**
237
+ * Name of shipping method chosen for the order (for example, "Standard Shipping")
238
+ */
239
+ shipping_method?: string;
240
+ };
241
+ /**
242
+ * State in the shipping address for the order
243
+ */
244
+ shipping_state?: string;
245
+ /**
246
+ * Zipcode in the shipping address for the order
247
+ */
248
+ shipping_zipcode?: string;
249
+ /**
250
+ * Total tax associated with the transaction
251
+ */
252
+ tax?: number;
253
+ /**
254
+ * Order metadata "template_id"
255
+ */
256
+ template_id?: number;
257
+ /**
258
+ * Revenue ($) with discounts and coupons added in.
259
+ */
260
+ total?: number;
261
+ /**
262
+ * Tracking IDs for third party integrations
263
+ */
264
+ tracking_ids?: {
265
+ [k: string]: unknown;
266
+ };
267
+ }
268
+ export interface Product {
269
+ /**
270
+ * Product affiliation to designate a supplying company or brick and mortar store location (for example, "Google Store")
271
+ */
272
+ affiliation?: string;
273
+ /**
274
+ * Brand associated with the product
275
+ */
276
+ brand?: string;
277
+ /**
278
+ * Product belongs to a bundle
279
+ */
280
+ bundle?: boolean;
281
+ /**
282
+ * Product category
283
+ */
284
+ category?: string;
285
+ /**
286
+ * Short description of the product
287
+ */
288
+ description?: string;
289
+ /**
290
+ * Image URL of the product
291
+ */
292
+ image_url?: string;
293
+ /**
294
+ * Name of the product
295
+ */
296
+ name: string;
297
+ /**
298
+ * Option values of the product variant
299
+ */
300
+ option_values?: string[];
301
+ /**
302
+ * Position in the product list (for example, 3)
303
+ */
304
+ position?: number;
305
+ /**
306
+ * Price ($) of the product
307
+ */
308
+ price: number;
309
+ /**
310
+ * Database ID of the product
311
+ */
312
+ product_id: string;
313
+ /**
314
+ * SKU of the product variant
315
+ */
316
+ sku: string;
317
+ /**
318
+ * Slug of the product, often used in URLs (for example, "product-red")
319
+ */
320
+ slug?: string;
321
+ /**
322
+ * URL of the product page
323
+ */
324
+ url?: string;
325
+ /**
326
+ * Name of the product variant
327
+ */
328
+ variant?: string;
329
+ }
330
+ export interface Checkout {
331
+ /**
332
+ * Store or affiliation from which this transaction occurred (for example, "Google Store")
333
+ */
334
+ affiliation?: string;
335
+ /**
336
+ * Checkout provider (for example, "stripe")
337
+ */
338
+ checkout_type?: string;
339
+ /**
340
+ * Transaction coupon redeemed with the transaction
341
+ */
342
+ coupon?: string;
343
+ /**
344
+ * Currency code of the transaction (for example, "USD")
345
+ */
346
+ currency?: string;
347
+ /**
348
+ * Total discount associated with the transaction
349
+ */
350
+ discount?: number;
351
+ /**
352
+ * Order/transaction ID
353
+ */
354
+ order_id?: string;
355
+ /**
356
+ * Order number (for example, "CHORD-000111222")
357
+ */
358
+ order_name?: string;
359
+ /**
360
+ * Products in the checkout
361
+ */
362
+ products: LineItem[];
363
+ /**
364
+ * Revenue ($) associated with the transaction (excluding shipping and tax)
365
+ */
366
+ revenue?: number;
367
+ /**
368
+ * Shipping cost associated with the transaction
369
+ */
370
+ shipping?: number;
371
+ /**
372
+ * Total tax associated with the transaction
373
+ */
374
+ tax?: number;
375
+ /**
376
+ * Revenue ($) with discounts and coupons added in
377
+ */
378
+ value?: number;
379
+ }
@@ -0,0 +1 @@
1
+ export {};