@recras/online-booking-js 1.10.2 → 2.0.0

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.
@@ -48,54 +48,50 @@ class RecrasEventHelper {
48
48
  return this.eventsEnabled.includes(name);
49
49
  }
50
50
 
51
- sendEvent(cat, action, label = undefined, value = undefined) {
52
- let event;
53
-
54
- try {
55
- event = new Event(RecrasEventHelper.PREFIX_GLOBAL + ':' + cat + ':' + action);
56
- } catch (e) {
57
- // IE
58
- event = document.createEvent('Event');
59
- event.initEvent(action, true, true);
51
+ ga4EventMap(action) {
52
+ let map = {
53
+ [RecrasEventHelper.EVENT_BOOKING_PACKAGE_CHANGED]: 'select_content',
54
+ [RecrasEventHelper.EVENT_BOOKING_REDIRECT_PAYMENT]: 'begin_checkout',
55
+ [RecrasEventHelper.EVENT_VOUCHER_TEMPLATE_CHANGED]: 'select_content',
56
+ [RecrasEventHelper.EVENT_VOUCHER_REDIRECT_PAYMENT]: 'begin_checkout',
57
+ };
58
+
59
+ if (map[action] === undefined) {
60
+ return false;
61
+ }
62
+ return map[action];
63
+ }
64
+
65
+ sendAnalyticsEvent(cat, action, label = undefined, value = undefined, ga4Value = undefined) {
66
+ if (typeof window.gtag !== 'function') {
67
+ return;
68
+ }
69
+
70
+ if (this.ga4EventMap(action) && ga4Value) {
71
+ // v4
72
+ window.gtag('event', this.ga4EventMap(action), ga4Value);
73
+ return;
74
+ }
75
+
76
+ // Global Site Tag (v3)
77
+ let eventData = {
78
+ event_category: RecrasEventHelper.PREFIX_GLOBAL + ':' + cat,
79
+ };
80
+ if (label) {
81
+ eventData.event_label = label;
60
82
  }
83
+ if (value) {
84
+ eventData.value = value;
85
+ }
86
+ window.gtag('event', action, eventData);
87
+ }
61
88
 
89
+ sendEvent(cat, action, label = undefined, value = undefined, ga4Value = undefined) {
62
90
  if (this.analyticsEnabled && this.eventEnabled(action)) {
63
- if (typeof window.gtag === 'function') {
64
- // Global Site Tag - the more modern variant
65
- let eventData = {
66
- event_category: RecrasEventHelper.PREFIX_GLOBAL + ':' + cat,
67
- };
68
- if (label) {
69
- eventData.event_label = label;
70
- }
71
- if (value) {
72
- eventData.value = value;
73
- }
74
- window.gtag('event', action, eventData);
75
- } else if (typeof window.ga === 'function') {
76
- // "Old" Google Analytics
77
- let eventData = {
78
- hitType: 'event',
79
- eventCategory: RecrasEventHelper.PREFIX_GLOBAL + ':' + cat,
80
- eventAction: action,
81
- };
82
- if (label) {
83
- eventData.eventLabel = label;
84
- }
85
- if (value) {
86
- eventData.eventValue = value;
87
- }
88
- // Google Analytics via Google Tag Manager doesn't work without a prefix
89
- window.ga(function() {
90
- let prefix = window.ga.getAll()[0].get('name');
91
- if (prefix) {
92
- prefix += '.';
93
- }
94
- window.ga(prefix + 'send', eventData);
95
- })
96
- }
91
+ this.sendAnalyticsEvent(cat, action, label, value, ga4Value);
97
92
  }
98
93
 
94
+ const event = new Event(RecrasEventHelper.PREFIX_GLOBAL + ':' + cat + ':' + action);
99
95
  return document.dispatchEvent(event);
100
96
  }
101
97
 
package/src/vouchers.js CHANGED
@@ -43,6 +43,16 @@ class RecrasVoucher {
43
43
  this.element.insertAdjacentHTML('beforeend', msg);
44
44
  }
45
45
 
46
+ formatGA4Item() {
47
+ return [
48
+ {
49
+ item_name: this.selectedTemplate.name,
50
+ price: this.selectedTemplate.price,
51
+ quantity: parseInt(this.findElement('#number-of-vouchers').value),
52
+ }
53
+ ];
54
+ }
55
+
46
56
  buyTemplate() {
47
57
  let status = this.contactForm.checkRequiredCheckboxes();
48
58
  if (!status) {
@@ -53,7 +63,7 @@ class RecrasVoucher {
53
63
  RecrasEventHelper.PREFIX_VOUCHER,
54
64
  RecrasEventHelper.EVENT_VOUCHER_VOUCHER_SUBMITTED,
55
65
  this.selectedTemplate.name,
56
- this.selectedTemplate.id
66
+ Math.round(this.totalPrice())
57
67
  );
58
68
  this.findElement('.buyTemplate').setAttribute('disabled', 'disabled');
59
69
 
@@ -72,7 +82,12 @@ class RecrasVoucher {
72
82
  RecrasEventHelper.PREFIX_VOUCHER,
73
83
  RecrasEventHelper.EVENT_VOUCHER_REDIRECT_PAYMENT,
74
84
  null,
75
- Math.round(this.totalPrice())
85
+ Math.round(this.totalPrice()),
86
+ {
87
+ currency: this.languageHelper.currency,
88
+ value: this.totalPrice(),
89
+ items: this.formatGA4Item(),
90
+ }
76
91
  );
77
92
  window.top.location.href = json.payment_url;
78
93
  } else {
@@ -94,7 +109,11 @@ class RecrasVoucher {
94
109
  RecrasEventHelper.PREFIX_VOUCHER,
95
110
  RecrasEventHelper.EVENT_VOUCHER_TEMPLATE_CHANGED,
96
111
  null,
97
- templateID
112
+ templateID,
113
+ {
114
+ content_type: 'voucher',
115
+ item_id: templateID,
116
+ }
98
117
  );
99
118
  }
100
119
 
@@ -108,7 +108,6 @@ describe('RecrasOptions', () => {
108
108
  let options = new RecrasOptions({
109
109
  element: document.createElement('div'),
110
110
  recras_hostname: 'demo.recras.nl',
111
- analytics: function() {},
112
111
  analyticsEvents: 'foo',
113
112
  });
114
113
  expect(options.getAnalyticsEvents().length).toBeGreaterThan(0);
@@ -118,7 +117,6 @@ describe('RecrasOptions', () => {
118
117
  let options = new RecrasOptions({
119
118
  element: document.createElement('div'),
120
119
  recras_hostname: 'demo.recras.nl',
121
- analytics: function() {},
122
120
  analyticsEvents: [],
123
121
  });
124
122
  expect(options.getAnalyticsEvents().length).toBeGreaterThan(0);
@@ -128,7 +126,6 @@ describe('RecrasOptions', () => {
128
126
  let options = new RecrasOptions({
129
127
  element: document.createElement('div'),
130
128
  recras_hostname: 'demo.recras.nl',
131
- analytics: function() {},
132
129
  analyticsEvents: ['foo', RecrasEventHelper.EVENT_BOOKING_BOOKING_SUBMITTED],
133
130
  });
134
131
  expect(options.getAnalyticsEvents()).toEqual([RecrasEventHelper.EVENT_BOOKING_BOOKING_SUBMITTED]);
package/upgrading.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 1.11.0 -> 2.0.0
2
+ * Support for Google Analytics v2 has been dropped.
3
+ * Support for Internet Explorer (all versions) and old Edge (12-15) has been removed.
4
+ * Option `showSubmit` has been removed. It was renamed to `standalone` in version 1.3.0
5
+
6
+ # 1.10.2 -> 1.10.3
7
+ * The value of "BuyInProgress" events sent to Google Analytics was changed from package ID to total price. This is true for both bookings and vouchers. We consider this a bugfix and not a backwards-compatibility breaking change.
8
+
1
9
  # 1.2.0 -> 1.3.0
2
10
  * Option `showSubmit` for contact forms (only used internally) is now named `standalone`. The old option will remain as alias until the next major version.
3
11