@ordergroove/offers 2.28.6-alpha-PR-690-4.5 → 2.28.6

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.
@@ -76,8 +76,6 @@
76
76
  --og-tooltip-size: 10px;
77
77
  --og-tooltip-color: rgba(245, 166, 35, 1);
78
78
 
79
- --og-checkbox-border-color: #000000;
80
-
81
79
  --og-upsell-background: rgba(202, 25, 148, 1);
82
80
  --og-upsell-family: Arial, Helvetica, sans-serif;
83
81
  --og-upsell-size: 13px;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ordergroove/offers",
3
- "version": "2.28.6-alpha-PR-690-4.5+df9bd648",
3
+ "version": "2.28.6",
4
4
  "description": "offer state component",
5
5
  "author": "Eugenio Lattanzio <eugenio63@gmail.com>",
6
6
  "homepage": "https://github.com/ordergroove/plush-toys#readme",
@@ -45,7 +45,7 @@
45
45
  "throttle-debounce": "^2.1.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@ordergroove/offers-templates": "^0.4.20-alpha-PR-690-4.8+df9bd648"
48
+ "@ordergroove/offers-templates": "^0.4.19"
49
49
  },
50
- "gitHead": "df9bd64861d17c6f78736f5283a29f18afc9ddf7"
50
+ "gitHead": "8fcfa089277dc66d25e5d35f6a92e39b510078cf"
51
51
  }
package/src/core/store.js CHANGED
@@ -32,7 +32,7 @@ export function makeStore(reducer, ...extraMiddlewares) {
32
32
  }
33
33
  }
34
34
 
35
- const enhancer = composeEnhancers(applyMiddleware(...middlewares, ...extraMiddlewares));
35
+ const enhancer = composeEnhancers(applyMiddleware(...middlewares, ...extraMiddlewares.filter(it => it)));
36
36
  const store = createStore(reducer, initial, enhancer);
37
37
 
38
38
  window.og = window.og || {};
package/src/core/utils.ts CHANGED
@@ -123,3 +123,20 @@ export const mapFrequencyToSellingPlan = (sellingPlans, frequenciesEveryPeriod,
123
123
 
124
124
  return null;
125
125
  };
126
+
127
+ export function getOrCreateHidden(parent, name, value) {
128
+ let input = parent.querySelector(`[name="${name}"]`);
129
+ if (input && !value) {
130
+ input.remove();
131
+ return;
132
+ }
133
+ if (!input && value) {
134
+ input = document.createElement('input');
135
+ input.type = 'hidden';
136
+ input.name = name;
137
+ parent.appendChild(input);
138
+ }
139
+ if (input) {
140
+ input.value = value;
141
+ }
142
+ }
package/src/index.js CHANGED
@@ -6,9 +6,11 @@ import shopifyMiddleware from './shopify/shopifyMiddleware';
6
6
  import platform from './platform';
7
7
  import { autoInitializeOffers, onReady } from './core/utils';
8
8
  import { authorizeShopifyCustomer } from './shopify/shopifyBootstrap';
9
+ import shopifyTrackingMiddleware from './shopify/shopifyTrackingMiddleware';
9
10
 
10
11
  export const store = makeStore(
11
- ...(platform?.shopify_selling_plans ? [shopifyReducer, shopifyMiddleware] : [defaultReducer])
12
+ ...(platform?.shopify_selling_plans ? [shopifyReducer, shopifyMiddleware] : [defaultReducer]),
13
+ platform.shopify && shopifyTrackingMiddleware
12
14
  );
13
15
 
14
16
  export const offers = makeApi(store);
package/src/platform.ts CHANGED
@@ -3,7 +3,7 @@ import { getMainJs } from './core/utils';
3
3
  const script = getMainJs();
4
4
 
5
5
  export default {
6
- shopify: typeof script?.dataset.shopifySellingPlans !== 'undefined',
6
+ shopify: typeof window.Shopify !== 'undefined',
7
7
  // detect in the frontend if we should use shopify selling plans or not
8
8
  shopify_selling_plans: typeof script?.dataset.shopifySellingPlans !== 'undefined'
9
9
  };
@@ -13,7 +13,7 @@ import {
13
13
  } from '../core/constants';
14
14
 
15
15
  import { makeSubscribedSelector } from '../core/selectors';
16
- import { safeProductId } from '../core/utils';
16
+ import { getOrCreateHidden, safeProductId } from '../core/utils';
17
17
 
18
18
  const SHOPIFY_ROOT = window.Shopify?.routes?.root || '/';
19
19
  const CART_PAGE_URL = '/cart';
@@ -142,9 +142,6 @@ export async function synchronizeCartOptin(action: any, store: any) {
142
142
  const trackingEvent = getTrackingEvent(action);
143
143
 
144
144
  if (!offerElement?.isCart) {
145
- if (offerElement) {
146
- updateTrackingInputs(offerElement.product.id, trackingEvent[0], trackingEvent[1]);
147
- }
148
145
  return;
149
146
  }
150
147
 
@@ -288,52 +285,6 @@ export function getTrackingEvent(action): Array<string> {
288
285
  return [key, value.join(',')];
289
286
  }
290
287
 
291
- /**
292
- * Creates or updates a hidden input used for tracking on non-cart pages
293
- *
294
- * @param product_id a product ID
295
- * @param name an input name, og_<timestamp in seconds>
296
- * @param value an input value, <tracking event>
297
- * @return {undefined}
298
- */
299
- export function updateTrackingInputs(product_id: string, name: string, value: string) {
300
- const store2FormElementSelector = `[name="id"][value="${product_id}"]`;
301
- const store1FormElementSelector = `form[action="/cart/add"] option[value="${product_id}"]`;
302
- if (!name) return;
303
- let cartAddFormElements = document.querySelectorAll(store2FormElementSelector);
304
- if (!cartAddFormElements.length) {
305
- cartAddFormElements = document.querySelectorAll(store1FormElementSelector);
306
- }
307
- [...cartAddFormElements].forEach((cartAddFormElement: HTMLInputElement) => {
308
- const parent = cartAddFormElement.form;
309
-
310
- let input = parent?.querySelector(`[name="${name}"]`) as HTMLInputElement;
311
- if (!input) {
312
- input = document.createElement('input');
313
- input.type = 'hidden';
314
- input.name = `attributes[${name}]`;
315
- parent?.appendChild(input);
316
- }
317
- input.value = value;
318
- });
319
- }
320
-
321
- export function getOrCreateHidden(parent, name, value) {
322
- let input = parent.querySelector(`[name="${name}"]`);
323
- if (input && !value) {
324
- input.remove();
325
- return;
326
- }
327
- if (!input && value) {
328
- input = document.createElement('input');
329
- input.type = 'hidden';
330
- input.name = name;
331
- parent.appendChild(input);
332
- }
333
- if (input) {
334
- input.value = value;
335
- }
336
- }
337
288
  /**
338
289
  * // update <input type="hidden" name="selling_plan"/> if available
339
290
  *
@@ -0,0 +1,52 @@
1
+ import { OPTIN_PRODUCT, OPTOUT_PRODUCT, PRODUCT_CHANGE_FREQUENCY } from '../core/constants';
2
+ import { getTrackingEvent } from './shopifyMiddleware';
3
+
4
+ /**
5
+ * Creates or updates a hidden input used for tracking on non-cart pages
6
+ *
7
+ * @param product_id a product ID
8
+ * @param name an input name, og_<timestamp in seconds>
9
+ * @param value an input value, <tracking event>
10
+ * @return {undefined}
11
+ */
12
+ export function updateTrackingInputs(product_id: string, name: string, value: string) {
13
+ const store2FormElementSelector = `[name="id"][value="${product_id}"]`;
14
+ const store1FormElementSelector = `form[action="/cart/add"] option[value="${product_id}"]`;
15
+ if (!name) return;
16
+ let cartAddFormElements = document.querySelectorAll(store2FormElementSelector);
17
+ if (!cartAddFormElements.length) {
18
+ cartAddFormElements = document.querySelectorAll(store1FormElementSelector);
19
+ }
20
+ [...cartAddFormElements].forEach((cartAddFormElement: HTMLInputElement) => {
21
+ const parent = cartAddFormElement.form;
22
+
23
+ let input = parent?.querySelector(`[name="${name}"]`) as HTMLInputElement;
24
+ if (!input) {
25
+ input = document.createElement('input');
26
+ input.type = 'hidden';
27
+ input.name = `attributes[${name}]`;
28
+ parent?.appendChild(input);
29
+ }
30
+ input.value = value;
31
+ });
32
+ }
33
+
34
+ export default function shopifyTrackingMiddleware(store) {
35
+ return next => action => {
36
+ next(action);
37
+
38
+ switch (action.type) {
39
+ case OPTIN_PRODUCT:
40
+ case OPTOUT_PRODUCT:
41
+ case PRODUCT_CHANGE_FREQUENCY:
42
+ const offerElement = action.payload.offer;
43
+ const trackingEvent = getTrackingEvent(action);
44
+
45
+ if (offerElement && !offerElement.isCart) {
46
+ updateTrackingInputs(offerElement.product.id, trackingEvent[0], trackingEvent[1]);
47
+ }
48
+ break;
49
+ default:
50
+ }
51
+ };
52
+ }