@magento/experience-platform-connector 1.0.0-alpha.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.
Files changed (56) hide show
  1. package/intercept.js +24 -0
  2. package/package.json +30 -0
  3. package/src/__tests__/__snapshots__/utils.spec.js.snap +137 -0
  4. package/src/__tests__/utils.spec.js +52 -0
  5. package/src/config.js +31 -0
  6. package/src/handleEvent.js +9 -0
  7. package/src/handlers/__tests__/__mocks__/cartAddItem.js +36 -0
  8. package/src/handlers/__tests__/__mocks__/cartPageView.js +880 -0
  9. package/src/handlers/__tests__/__mocks__/categoryPageView.js +9 -0
  10. package/src/handlers/__tests__/__mocks__/checkoutPageView.js +138 -0
  11. package/src/handlers/__tests__/__mocks__/completeCheckout.js +156 -0
  12. package/src/handlers/__tests__/__mocks__/createAccount.js +9 -0
  13. package/src/handlers/__tests__/__mocks__/editAccount.js +9 -0
  14. package/src/handlers/__tests__/__mocks__/miniCartView.js +846 -0
  15. package/src/handlers/__tests__/__mocks__/orderConfirmationPageView.js +67 -0
  16. package/src/handlers/__tests__/__mocks__/pageView.js +7 -0
  17. package/src/handlers/__tests__/__mocks__/placeOrderButtonClicked.js +161 -0
  18. package/src/handlers/__tests__/__mocks__/productPageView.js +15 -0
  19. package/src/handlers/__tests__/__mocks__/searchPageRequest.js +22 -0
  20. package/src/handlers/__tests__/__mocks__/searchRequestSent.js +34 -0
  21. package/src/handlers/__tests__/__mocks__/searchResponseReceived.js +106 -0
  22. package/src/handlers/__tests__/__snapshots__/shoppingMiniCartView.spec.js.snap +137 -0
  23. package/src/handlers/__tests__/addToCart.spec.js +73 -0
  24. package/src/handlers/__tests__/categoryPageView.spec.js +55 -0
  25. package/src/handlers/__tests__/completeCheckout.spec.js +70 -0
  26. package/src/handlers/__tests__/createAccount.spec.js +43 -0
  27. package/src/handlers/__tests__/editAccount.spec.js +43 -0
  28. package/src/handlers/__tests__/pageView.spec.js +46 -0
  29. package/src/handlers/__tests__/placeOrder.spec.js +55 -0
  30. package/src/handlers/__tests__/productPageView.spec.js +64 -0
  31. package/src/handlers/__tests__/searchRequestSent.spec.js +119 -0
  32. package/src/handlers/__tests__/searchResponseReceived.spec.js +143 -0
  33. package/src/handlers/__tests__/shoppingCartPageView.spec.js +198 -0
  34. package/src/handlers/__tests__/shoppingMiniCartView.spec.js +36 -0
  35. package/src/handlers/__tests__/signIn.spec.js +73 -0
  36. package/src/handlers/__tests__/startCheckout.spec.js +193 -0
  37. package/src/handlers/addToCart.js +60 -0
  38. package/src/handlers/categoryPageView.js +34 -0
  39. package/src/handlers/completeCheckout.js +49 -0
  40. package/src/handlers/createAccount.js +25 -0
  41. package/src/handlers/editAccount.js +25 -0
  42. package/src/handlers/pageView.js +26 -0
  43. package/src/handlers/placeOrder.js +32 -0
  44. package/src/handlers/productPageView.js +41 -0
  45. package/src/handlers/searchRequestSent.js +38 -0
  46. package/src/handlers/searchResponseReceived.js +39 -0
  47. package/src/handlers/shoppingCartPageView.js +45 -0
  48. package/src/handlers/shoppingMiniCartView.js +31 -0
  49. package/src/handlers/signIn.js +29 -0
  50. package/src/handlers/startCheckout.js +45 -0
  51. package/src/hooks/useExtensionContext.js +21 -0
  52. package/src/main.js +116 -0
  53. package/src/queries/getExtensionContext.js +31 -0
  54. package/src/utils.js +101 -0
  55. package/src/wrappers/wrapUseAccountMenu.js +29 -0
  56. package/src/wrappers/wrapUseAutocomplete.js +48 -0
@@ -0,0 +1,198 @@
1
+ import handler from '../shoppingCartPageView';
2
+
3
+ import miniCartViewEvent from './__mocks__/miniCartView';
4
+ import cartPageViewEvent from './__mocks__/cartPageView';
5
+
6
+ describe('canHandle()', () => {
7
+ it('returns true for the correct event type', () => {
8
+ expect(handler.canHandle(cartPageViewEvent)).toBeTruthy();
9
+ });
10
+
11
+ it('returns false for non supported event types', () => {
12
+ expect(handler.canHandle(miniCartViewEvent)).toBeFalsy();
13
+ });
14
+ });
15
+
16
+ describe('handle()', () => {
17
+ it('calls the correct sdk functions with the correct context value', () => {
18
+ const mockSdk = {
19
+ context: {
20
+ setShoppingCart: jest.fn(),
21
+ setPage: jest.fn()
22
+ },
23
+ publish: {
24
+ shoppingCartView: jest.fn(),
25
+ pageView: jest.fn()
26
+ }
27
+ };
28
+
29
+ handler.handle(mockSdk, cartPageViewEvent);
30
+
31
+ expect(mockSdk.context.setShoppingCart).toHaveBeenCalledTimes(1);
32
+ expect(mockSdk.context.setShoppingCart.mock.calls[0][0])
33
+ .toMatchInlineSnapshot(`
34
+ Object {
35
+ "giftMessageSelected": false,
36
+ "giftWrappingSelected": false,
37
+ "id": "kAR5Gg6uPC6J5wGY0ebecyKfX905epmU",
38
+ "items": Array [
39
+ Object {
40
+ "configurableOptions": Array [
41
+ Object {
42
+ "id": 157,
43
+ "optionLabel": "Fashion Color",
44
+ "valueId": "Y29uZmlndXJhYmxlLzE1Ny8zMQ==",
45
+ "valueLabel": "Peach",
46
+ },
47
+ Object {
48
+ "id": 190,
49
+ "optionLabel": "Fashion Size",
50
+ "valueId": "Y29uZmlndXJhYmxlLzE5MC80Mw==",
51
+ "valueLabel": "L",
52
+ },
53
+ ],
54
+ "formattedPrice": "",
55
+ "id": "MjQ2Ng==",
56
+ "prices": Object {
57
+ "__typename": "CartItemPrices",
58
+ "price": Object {
59
+ "__typename": "Money",
60
+ "currency": "USD",
61
+ "value": 78,
62
+ },
63
+ "row_total": Object {
64
+ "__typename": "Money",
65
+ "value": 78,
66
+ },
67
+ "total_item_discount": Object {
68
+ "__typename": "Money",
69
+ "value": 0,
70
+ },
71
+ },
72
+ "product": Object {
73
+ "canonicalUrl": "rowena-skirt",
74
+ "mainImageUrl": "https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/media/catalog/product/cache/609faca36a4bc16a754bc2f43c184970/v/s/vsk02-ll_main_2.jpg",
75
+ "name": "Rowena Skirt",
76
+ "pricing": Object {
77
+ "currencyCode": "USD",
78
+ "maximalPrice": 78,
79
+ "minimalPrice": 78,
80
+ "regularPrice": 78,
81
+ },
82
+ "productType": "ConfigurableProduct",
83
+ "sku": "VSK02",
84
+ },
85
+ "quantity": 1,
86
+ },
87
+ Object {
88
+ "configurableOptions": null,
89
+ "formattedPrice": "",
90
+ "id": "MjQ4Mg==",
91
+ "prices": Object {
92
+ "__typename": "CartItemPrices",
93
+ "price": Object {
94
+ "__typename": "Money",
95
+ "currency": "USD",
96
+ "value": 68,
97
+ },
98
+ "row_total": Object {
99
+ "__typename": "Money",
100
+ "value": 136,
101
+ },
102
+ "total_item_discount": Object {
103
+ "__typename": "Money",
104
+ "value": 0,
105
+ },
106
+ },
107
+ "product": Object {
108
+ "canonicalUrl": "silver-cirque-earrings",
109
+ "mainImageUrl": "https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/media/catalog/product/cache/609faca36a4bc16a754bc2f43c184970/v/a/va17-si_main.jpg",
110
+ "name": "Silver Cirque Earrings",
111
+ "pricing": Object {
112
+ "currencyCode": "USD",
113
+ "maximalPrice": 68,
114
+ "minimalPrice": 68,
115
+ "regularPrice": 68,
116
+ },
117
+ "productType": "SimpleProduct",
118
+ "sku": "VA17-SI-NA",
119
+ },
120
+ "quantity": 2,
121
+ },
122
+ Object {
123
+ "configurableOptions": Array [
124
+ Object {
125
+ "id": 157,
126
+ "optionLabel": "Fashion Color",
127
+ "valueId": "Y29uZmlndXJhYmxlLzE1Ny8zMQ==",
128
+ "valueLabel": "Peach",
129
+ },
130
+ Object {
131
+ "id": 190,
132
+ "optionLabel": "Fashion Size",
133
+ "valueId": "Y29uZmlndXJhYmxlLzE5MC80NA==",
134
+ "valueLabel": "M",
135
+ },
136
+ ],
137
+ "formattedPrice": "",
138
+ "id": "MjQ4Mw==",
139
+ "prices": Object {
140
+ "__typename": "CartItemPrices",
141
+ "price": Object {
142
+ "__typename": "Money",
143
+ "currency": "USD",
144
+ "value": 48,
145
+ },
146
+ "row_total": Object {
147
+ "__typename": "Money",
148
+ "value": 144,
149
+ },
150
+ "total_item_discount": Object {
151
+ "__typename": "Money",
152
+ "value": 0,
153
+ },
154
+ },
155
+ "product": Object {
156
+ "canonicalUrl": "antonia-infinity-scarf",
157
+ "mainImageUrl": "https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/media/catalog/product/cache/609faca36a4bc16a754bc2f43c184970/v/a/va04-ll_main_2.jpg",
158
+ "name": "Antonia Infinity Scarf",
159
+ "pricing": Object {
160
+ "currencyCode": "USD",
161
+ "maximalPrice": 48,
162
+ "minimalPrice": 48,
163
+ "regularPrice": 48,
164
+ },
165
+ "productType": "ConfigurableProduct",
166
+ "sku": "VA04",
167
+ },
168
+ "quantity": 3,
169
+ },
170
+ ],
171
+ "possibleOnepageCheckout": false,
172
+ "prices": Object {
173
+ "subtotalExcludingTax": Object {
174
+ "currency": "USD",
175
+ "value": 358,
176
+ },
177
+ },
178
+ }
179
+ `);
180
+
181
+ expect(mockSdk.publish.shoppingCartView).toHaveBeenCalledTimes(1);
182
+
183
+ expect(mockSdk.context.setPage).toHaveBeenCalledTimes(1);
184
+ expect(mockSdk.context.setPage.mock.calls[0][0]).toMatchInlineSnapshot(`
185
+ Object {
186
+ "eventType": "visibilityHidden",
187
+ "maxXOffset": 0,
188
+ "maxYOffset": 0,
189
+ "minXOffset": 0,
190
+ "minYOffset": 0,
191
+ "pageName": "Cart",
192
+ "pageType": "Cart",
193
+ }
194
+ `);
195
+
196
+ expect(mockSdk.publish.pageView).toHaveBeenCalledTimes(1);
197
+ });
198
+ });
@@ -0,0 +1,36 @@
1
+ import handler from '../shoppingMiniCartView';
2
+
3
+ import miniCartViewEvent from './__mocks__/miniCartView';
4
+ import cartPageViewEvent from './__mocks__/cartPageView';
5
+
6
+ describe('canHandle()', () => {
7
+ it('returns true for the correct event type', () => {
8
+ expect(handler.canHandle(miniCartViewEvent)).toBeTruthy();
9
+ });
10
+
11
+ it('returns false for non supported event types', () => {
12
+ expect(handler.canHandle(cartPageViewEvent)).toBeFalsy();
13
+ });
14
+ });
15
+
16
+ describe('handle()', () => {
17
+ it('calls the correct sdk functions with the correct context value', () => {
18
+ const mockSdk = {
19
+ context: {
20
+ setShoppingCart: jest.fn()
21
+ },
22
+ publish: {
23
+ shoppingCartView: jest.fn()
24
+ }
25
+ };
26
+
27
+ handler.handle(mockSdk, miniCartViewEvent);
28
+
29
+ expect(mockSdk.context.setShoppingCart).toHaveBeenCalledTimes(1);
30
+ expect(
31
+ mockSdk.context.setShoppingCart.mock.calls[0][0]
32
+ ).toMatchSnapshot();
33
+
34
+ expect(mockSdk.publish.shoppingCartView).toHaveBeenCalledTimes(1);
35
+ });
36
+ });
@@ -0,0 +1,73 @@
1
+ import handler from '../signIn';
2
+
3
+ describe('canHandle()', () => {
4
+ it('returns true for the correct event type', () => {
5
+ const mockEvent = {
6
+ type: 'USER_SIGN_IN',
7
+ payload: {}
8
+ };
9
+ expect(handler.canHandle(mockEvent)).toBeTruthy();
10
+ });
11
+
12
+ it('returns false for non supported event types', () => {
13
+ const mockEvent = {
14
+ type: 'USER_SIGN_OUT',
15
+ payload: {}
16
+ };
17
+ expect(handler.canHandle(mockEvent)).toBeFalsy();
18
+ });
19
+ });
20
+
21
+ describe('handle()', () => {
22
+ it('calls the correct sdk functions with the correct context value', () => {
23
+ const mockSdk = {
24
+ context: {
25
+ setAccount: jest.fn(),
26
+ setShopper: jest.fn()
27
+ },
28
+ publish: {
29
+ signIn: jest.fn()
30
+ }
31
+ };
32
+
33
+ const mockEvent = {
34
+ type: 'USER_SIGN_IN',
35
+ payload: {
36
+ email: 'doctor.strange@fake.email',
37
+ firstname: 'Stephen',
38
+ is_subscribed: false,
39
+ lastname: 'Strange',
40
+ __typename: 'Customer'
41
+ }
42
+ };
43
+
44
+ handler.handle(mockSdk, mockEvent);
45
+
46
+ expect(mockSdk.context.setShopper).toHaveBeenCalledTimes(1);
47
+ expect(mockSdk.context.setShopper.mock.calls[0][0])
48
+ .toMatchInlineSnapshot(`
49
+ Object {
50
+ "shopperId": "logged-in",
51
+ }
52
+ `);
53
+
54
+ expect(mockSdk.context.setAccount).toHaveBeenCalledTimes(1);
55
+ expect(mockSdk.context.setAccount.mock.calls[0][0])
56
+ .toMatchInlineSnapshot(`
57
+ Object {
58
+ "emailAddress": "doctor.strange@fake.email",
59
+ "firstName": "Stephen",
60
+ "lastName": "Strange",
61
+ }
62
+ `);
63
+
64
+ expect(mockSdk.publish.signIn).toHaveBeenCalledTimes(1);
65
+ expect(mockSdk.publish.signIn.mock.calls[0][0]).toMatchInlineSnapshot(`
66
+ Object {
67
+ "personalEmail": Object {
68
+ "address": "doctor.strange@fake.email",
69
+ },
70
+ }
71
+ `);
72
+ });
73
+ });
@@ -0,0 +1,193 @@
1
+ import handler from '../startCheckout';
2
+ import startCheckoutEvent from './__mocks__/checkoutPageView';
3
+
4
+ describe('canHandle()', () => {
5
+ it('returns true for the correct event type', () => {
6
+ expect(handler.canHandle(startCheckoutEvent)).toBeTruthy();
7
+ });
8
+
9
+ it('returns false for non supported event types', () => {
10
+ const mockEvent = {
11
+ type: 'USER_SIGN_OUT',
12
+ payload: {}
13
+ };
14
+ expect(handler.canHandle(mockEvent)).toBeFalsy();
15
+ });
16
+ });
17
+
18
+ describe('handle()', () => {
19
+ it('calls the correct sdk functions with the correct context value', () => {
20
+ const mockSdk = {
21
+ context: {
22
+ setPage: jest.fn(),
23
+ setShoppingCart: jest.fn()
24
+ },
25
+ publish: {
26
+ pageView: jest.fn(),
27
+ initiateCheckout: jest.fn()
28
+ }
29
+ };
30
+
31
+ handler.handle(mockSdk, startCheckoutEvent);
32
+
33
+ expect(mockSdk.context.setPage).toHaveBeenCalledTimes(1);
34
+ expect(mockSdk.context.setPage.mock.calls[0][0]).toMatchInlineSnapshot(`
35
+ Object {
36
+ "eventType": "visibilityHidden",
37
+ "maxXOffset": 0,
38
+ "maxYOffset": 0,
39
+ "minXOffset": 0,
40
+ "minYOffset": 0,
41
+ "pageName": "Checkout",
42
+ "pageType": "Checkout",
43
+ }
44
+ `);
45
+
46
+ expect(mockSdk.context.setShoppingCart).toHaveBeenCalledTimes(1);
47
+ expect(mockSdk.context.setShoppingCart.mock.calls[0][0])
48
+ .toMatchInlineSnapshot(`
49
+ Object {
50
+ "giftMessageSelected": false,
51
+ "giftWrappingSelected": false,
52
+ "id": "adaIGWl4UsoKOGIeX17FPrnMq3bXHVZA",
53
+ "items": Array [
54
+ Object {
55
+ "configurableOptions": Array [
56
+ Object {
57
+ "id": undefined,
58
+ "optionLabel": "Fashion Color",
59
+ "valueId": "Y29uZmlndXJhYmxlLzE1Ny8zNQ==",
60
+ "valueLabel": "Mint",
61
+ },
62
+ Object {
63
+ "id": undefined,
64
+ "optionLabel": "Fashion Size",
65
+ "valueId": "Y29uZmlndXJhYmxlLzE5MC80OQ==",
66
+ "valueLabel": "6",
67
+ },
68
+ ],
69
+ "formattedPrice": "",
70
+ "id": "Mjk3Nw==",
71
+ "prices": Object {
72
+ "__typename": "CartItemPrices",
73
+ "price": Object {
74
+ "__typename": "Money",
75
+ "currency": "USD",
76
+ "value": 98,
77
+ },
78
+ "row_total": Object {
79
+ "__typename": "Money",
80
+ "value": 294,
81
+ },
82
+ "total_item_discount": Object {
83
+ "__typename": "Money",
84
+ "value": 0,
85
+ },
86
+ },
87
+ "product": Object {
88
+ "canonicalUrl": undefined,
89
+ "mainImageUrl": "https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/media/catalog/product/cache/609faca36a4bc16a754bc2f43c184970/v/p/vp08-rn_main_2.jpg",
90
+ "name": "Bella Eyelet Capris",
91
+ "pricing": Object {
92
+ "currencyCode": "USD",
93
+ "maximalPrice": 98,
94
+ "minimalPrice": 98,
95
+ "regularPrice": 98,
96
+ },
97
+ "productType": "ConfigurableProduct",
98
+ "sku": "VP08",
99
+ },
100
+ "quantity": 3,
101
+ },
102
+ Object {
103
+ "configurableOptions": Array [
104
+ Object {
105
+ "id": undefined,
106
+ "optionLabel": "Fashion Size",
107
+ "valueId": "Y29uZmlndXJhYmxlLzE5MC80NA==",
108
+ "valueLabel": "M",
109
+ },
110
+ ],
111
+ "formattedPrice": "",
112
+ "id": "Mjk3OQ==",
113
+ "prices": Object {
114
+ "__typename": "CartItemPrices",
115
+ "price": Object {
116
+ "__typename": "Money",
117
+ "currency": "USD",
118
+ "value": 38,
119
+ },
120
+ "row_total": Object {
121
+ "__typename": "Money",
122
+ "value": 38,
123
+ },
124
+ "total_item_discount": Object {
125
+ "__typename": "Money",
126
+ "value": 0,
127
+ },
128
+ },
129
+ "product": Object {
130
+ "canonicalUrl": undefined,
131
+ "mainImageUrl": "https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/media/catalog/product/cache/609faca36a4bc16a754bc2f43c184970/v/a/va09-br_main_2.jpg",
132
+ "name": "Thin Leather Braided Belt",
133
+ "pricing": Object {
134
+ "currencyCode": "USD",
135
+ "maximalPrice": 38,
136
+ "minimalPrice": 38,
137
+ "regularPrice": 38,
138
+ },
139
+ "productType": "ConfigurableProduct",
140
+ "sku": "VA09",
141
+ },
142
+ "quantity": 1,
143
+ },
144
+ Object {
145
+ "configurableOptions": null,
146
+ "formattedPrice": "",
147
+ "id": "Mjk4Nw==",
148
+ "prices": Object {
149
+ "__typename": "CartItemPrices",
150
+ "price": Object {
151
+ "__typename": "Money",
152
+ "currency": "USD",
153
+ "value": 98,
154
+ },
155
+ "row_total": Object {
156
+ "__typename": "Money",
157
+ "value": 98,
158
+ },
159
+ "total_item_discount": Object {
160
+ "__typename": "Money",
161
+ "value": 0,
162
+ },
163
+ },
164
+ "product": Object {
165
+ "canonicalUrl": undefined,
166
+ "mainImageUrl": "https://master-7rqtwti-mfwmkrjfqvbjk.us-4.magentosite.cloud/media/catalog/product/cache/609faca36a4bc16a754bc2f43c184970/v/a/va22-si_main.jpg",
167
+ "name": "Silver Amor Bangle Set",
168
+ "pricing": Object {
169
+ "currencyCode": "USD",
170
+ "maximalPrice": 98,
171
+ "minimalPrice": 98,
172
+ "regularPrice": 98,
173
+ },
174
+ "productType": "SimpleProduct",
175
+ "sku": "VA22-SI-NA",
176
+ },
177
+ "quantity": 1,
178
+ },
179
+ ],
180
+ "possibleOnepageCheckout": false,
181
+ "prices": Object {
182
+ "subtotalExcludingTax": Object {
183
+ "currency": "USD",
184
+ "value": 430,
185
+ },
186
+ },
187
+ }
188
+ `);
189
+
190
+ expect(mockSdk.publish.pageView).toHaveBeenCalledTimes(1);
191
+ expect(mockSdk.publish.initiateCheckout).toHaveBeenCalledTimes(1);
192
+ });
193
+ });
@@ -0,0 +1,60 @@
1
+ const canHandle = event => event.type === 'CART_ADD_ITEM';
2
+
3
+ const handle = (sdk, event) => {
4
+ const { payload } = event;
5
+
6
+ const {
7
+ cartId,
8
+ currencyCode,
9
+ priceTotal,
10
+ quantity,
11
+ name,
12
+ sku,
13
+ selectedOptions
14
+ } = payload;
15
+
16
+ const configurableOptions = selectedOptions
17
+ ? [
18
+ {
19
+ optionLabel: selectedOptions.attribute,
20
+ valueLabel: selectedOptions.value
21
+ }
22
+ ]
23
+ : null;
24
+
25
+ const cartItemContext = {
26
+ id: cartId,
27
+ prices: {
28
+ subtotalExcludingTax: {
29
+ value: priceTotal * quantity,
30
+ currency: currencyCode
31
+ }
32
+ },
33
+ items: [
34
+ {
35
+ product: {
36
+ name: name,
37
+ sku: sku,
38
+ configurableOptions: configurableOptions
39
+ },
40
+ prices: {
41
+ price: {
42
+ value: priceTotal,
43
+ currency: currencyCode
44
+ }
45
+ }
46
+ }
47
+ ],
48
+ possibleOnepageCheckout: false,
49
+ giftMessageSelected: false,
50
+ giftWrappingSelected: false
51
+ };
52
+
53
+ sdk.context.setShoppingCart(cartItemContext);
54
+ sdk.publish.addToCart();
55
+ };
56
+
57
+ export default {
58
+ canHandle,
59
+ handle
60
+ };
@@ -0,0 +1,34 @@
1
+ const canHandle = event => event.type === 'CATEGORY_PAGE_VIEW';
2
+
3
+ const handle = (sdk, event) => {
4
+ const { payload } = event;
5
+
6
+ const { name, url_key, url_path } = payload;
7
+
8
+ const categoryContext = {
9
+ name,
10
+ urlKey: url_key,
11
+ urlPath: url_path
12
+ };
13
+
14
+ sdk.context.setCategory(categoryContext);
15
+
16
+ // Send out page view event
17
+ const pageContext = {
18
+ pageType: 'Category',
19
+ pageName: name,
20
+ eventType: 'visibilityHidden',
21
+ maxXOffset: 0,
22
+ maxYOffset: 0,
23
+ minXOffset: 0,
24
+ minYOffset: 0
25
+ };
26
+
27
+ sdk.context.setPage(pageContext);
28
+ sdk.publish.pageView();
29
+ };
30
+
31
+ export default {
32
+ canHandle,
33
+ handle
34
+ };
@@ -0,0 +1,49 @@
1
+ const canHandle = event => event.type === 'ORDER_CONFIRMATION_PAGE_VIEW';
2
+
3
+ const handle = (sdk, event) => {
4
+ const { payload } = event;
5
+
6
+ const grandTotal = payload.amount.grand_total.value;
7
+
8
+ const { order_number, payment, shipping } = payload;
9
+
10
+ const orderContext = {
11
+ orderId: order_number,
12
+ grandTotal: grandTotal,
13
+ orderType: 'checkout',
14
+ payments: [
15
+ {
16
+ paymentMethodCode: payment.title,
17
+ paymentMethodName: payment.title,
18
+ total: grandTotal
19
+ }
20
+ ],
21
+ shipping: {
22
+ shippingMethod: shipping[0].method_title,
23
+ shippingAmount: shipping[0].amount.value
24
+ }
25
+ };
26
+
27
+ sdk.context.setOrder(orderContext);
28
+
29
+ sdk.publish.placeOrder();
30
+
31
+ // Send out page view event
32
+ const pageContext = {
33
+ pageType: 'Order Confirmation Page',
34
+ pageName: 'Order Confirmation',
35
+ eventType: 'visibilityHidden',
36
+ maxXOffset: 0,
37
+ maxYOffset: 0,
38
+ minXOffset: 0,
39
+ minYOffset: 0
40
+ };
41
+
42
+ sdk.context.setPage(pageContext);
43
+ sdk.publish.pageView();
44
+ };
45
+
46
+ export default {
47
+ canHandle,
48
+ handle
49
+ };
@@ -0,0 +1,25 @@
1
+ const canHandle = event => event.type === 'USER_CREATE_ACCOUNT';
2
+
3
+ const handle = (sdk, event) => {
4
+ const { payload } = event;
5
+
6
+ const { firstName, lastName, email } = payload;
7
+
8
+ const accountContext = {
9
+ firstName,
10
+ lastName,
11
+ emailAddress: email
12
+ };
13
+
14
+ sdk.context.setAccount(accountContext);
15
+ sdk.publish.createAccount({
16
+ personalEmail: {
17
+ address: email
18
+ }
19
+ });
20
+ };
21
+
22
+ export default {
23
+ canHandle,
24
+ handle
25
+ };