bukazu-portal-react 3.2.2 → 3.3.2

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bukazu-portal-react",
3
- "version": "3.2.2",
3
+ "version": "3.3.2",
4
4
  "description": "A package for loading the calendar and search module from bukazu loading into a react app.",
5
5
  "repository": "https://github.com/BUKAZU/React-portal",
6
6
  "scripts": {
@@ -29,7 +29,6 @@
29
29
  "autoprefixer": "^10.4.13",
30
30
  "chalk": "1.1.3",
31
31
  "cypress": "^13.1.0",
32
- "dotenv": "4.0.0",
33
32
  "eslint": "^8.49.0",
34
33
  "eslint-plugin-jsx-a11y": "^6.4.1",
35
34
  "eslint-plugin-prettier": "^4.2.1",
@@ -52,10 +51,10 @@
52
51
  "whatwg-fetch": "2.0.3"
53
52
  },
54
53
  "dependencies": {
55
- "@apollo/client": "^3.7.5",
54
+ "@apollo/client": "^3.11.8",
56
55
  "date-fns": "^2.29.3",
57
56
  "formik": "^2.2.9",
58
- "graphql": "^15.6.0",
57
+ "graphql": "^16.9.0",
59
58
  "react-date-picker": "^8.1.1",
60
59
  "react-intl": "^6.2.5",
61
60
  "react-paginate": "^8.1.4"
@@ -0,0 +1,51 @@
1
+ export async function TrackEvent(data: any) {
2
+ const cookie = getCookie('bu_portal_session');
3
+
4
+ const all_data = {
5
+ ...data,
6
+ url: window.location.href,
7
+ session_identifier: cookie
8
+ }
9
+ fetch("https://api.bukazu.com/tracking", {
10
+ method: "POST",
11
+ headers: {
12
+ "Content-Type": "application/json"
13
+ },
14
+ body: JSON.stringify(all_data)
15
+ }).then((response) => response.text())
16
+ .then((data) => {
17
+ setCookie('bu_portal_session', data, 14);
18
+ } );
19
+ }
20
+
21
+ export function getSessionIdentifier() {
22
+ const sessionIdentifier = getCookie('bu_portal_session');
23
+ if (sessionIdentifier === '') {
24
+ return null
25
+ } else {
26
+ return sessionIdentifier
27
+ }
28
+ }
29
+
30
+ function setCookie(cname, cvalue, exdays) {
31
+ const d = new Date();
32
+ d.setTime(d.getTime() + (exdays*24*60*60*1000));
33
+ let expires = "expires="+ d.toUTCString();
34
+ document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
35
+ }
36
+
37
+ function getCookie(cname: string) {
38
+ let name = cname + "=";
39
+ let decodedCookie = decodeURIComponent(document.cookie);
40
+ let ca = decodedCookie.split(';');
41
+ for(let i = 0; i <ca.length; i++) {
42
+ let c = ca[i];
43
+ while (c.charAt(0) == ' ') {
44
+ c = c.substring(1);
45
+ }
46
+ if (c.indexOf(name) == 0) {
47
+ return c.substring(name.length, c.length);
48
+ }
49
+ }
50
+ return "";
51
+ }
@@ -115,6 +115,8 @@ export const BOOKING_PRICE_QUERY = gql`
115
115
  company_name_label
116
116
  extra_fields_drivers_license_label
117
117
  extra_fields_destination_label
118
+ form_submit_text
119
+ form_submit_button_text
118
120
  booking_fields {
119
121
  id
120
122
  label
@@ -179,6 +181,7 @@ export const CREATE_BOOKING_MUTATION = gql`
179
181
  $departure_date: String!
180
182
  $costs: Json
181
183
  $extra_fields: String
184
+ $sessionIdentifier: String
182
185
  ) {
183
186
  createBooking(
184
187
  first_name: $first_name
@@ -214,6 +217,7 @@ export const CREATE_BOOKING_MUTATION = gql`
214
217
  comment: $comment
215
218
  costs: $costs
216
219
  extra_fields: $extra_fields
220
+ sessionIdentifier: $sessionIdentifier
217
221
  ) {
218
222
  booking_nr
219
223
  }
@@ -23,7 +23,7 @@ interface Props {
23
23
  }
24
24
 
25
25
  function App({ pageType, locale, filters }: Props): JSX.Element {
26
- const { portalCode, objectCode } = useContext(AppContext);
26
+ const { portalCode, objectCode } = useContext(AppContext);
27
27
 
28
28
  const { loading, error, data } = useQuery(PORTAL_QUERY, {
29
29
  variables: { id: portalCode }
@@ -5,11 +5,12 @@ import { BOOKING_PRICE_QUERY } from '../../_lib/queries';
5
5
  import { useQuery } from '@apollo/client';
6
6
  import { AppContext } from '../AppContext';
7
7
  import { CalendarContext } from './CalendarParts/CalendarContext';
8
-
8
+ import { TrackEvent } from '../../_lib/Tracking';
9
9
 
10
10
  function BookingForm(): JSX.Element {
11
- const { portalCode, objectCode } = useContext(AppContext);
12
- const { arrivalDate, departureDate } = useContext(CalendarContext)
11
+ const { portalCode, objectCode, locale } = useContext(AppContext);
12
+ const { arrivalDate, departureDate } = useContext(CalendarContext);
13
+
13
14
  const { data, loading, error } = useQuery(BOOKING_PRICE_QUERY, {
14
15
  variables: {
15
16
  portalCode,
@@ -31,12 +32,18 @@ function BookingForm(): JSX.Element {
31
32
 
32
33
  const result = data.PortalSite.houses[0];
33
34
 
34
- return (
35
- <FormCreator
36
- house={result}
37
- PortalSite={data.PortalSite}
38
- />
39
- );
35
+ TrackEvent({
36
+ house_code: objectCode,
37
+ portal_code: portalCode,
38
+ locale: locale,
39
+ interaction_type: 'booking_started',
40
+ interaction_data: {
41
+ arrival_date: arrivalDate.date,
42
+ departure_date: departureDate.date
43
+ }
44
+ });
45
+
46
+ return <FormCreator house={result} PortalSite={data.PortalSite} />;
40
47
  }
41
48
 
42
49
  export default BookingForm;
@@ -7,17 +7,25 @@ import { AppContext } from '../../AppContext';
7
7
  import { ApiError } from '../../Error';
8
8
  import Loading from '../../icons/loading.svg';
9
9
  import Calendar from '../Calendar';
10
+ import { TrackEvent } from '../../../_lib/Tracking';
10
11
 
11
12
  interface Props {
12
13
  PortalSite: PortalSiteType;
13
14
  }
14
15
 
15
16
  function GenerateCalendar({ PortalSite }: Props): JSX.Element {
16
- const { portalCode, objectCode } = useContext(AppContext);
17
+ const { portalCode, objectCode, locale } = useContext(AppContext);
17
18
  const { loading, error, data } = useQuery(SINGLE_HOUSE_QUERY, {
18
19
  variables: { portalCode, objectCode }
19
20
  });
20
21
 
22
+ TrackEvent({
23
+ house_code: objectCode,
24
+ portal_code: portalCode,
25
+ interaction_type: 'calendar_view',
26
+ locale: locale
27
+ });
28
+
21
29
  if (loading)
22
30
  return (
23
31
  <div>
@@ -22,6 +22,7 @@ import {
22
22
  CalendarContext,
23
23
  CalendarContextDispatch
24
24
  } from './CalendarParts/CalendarContext';
25
+ import { getSessionIdentifier } from '../../_lib/Tracking';
25
26
 
26
27
  interface Props {
27
28
  house: HouseType;
@@ -52,6 +53,10 @@ function FormCreator({ house, PortalSite }: Props): JSX.Element {
52
53
 
53
54
  const optBookingFieldsInitialized = initializeBookingFields(bookingFields);
54
55
 
56
+ const sessionIdentifier = getSessionIdentifier();
57
+
58
+ console.log({ sessionIdentifier });
59
+
55
60
  return (
56
61
  <Formik
57
62
  validate={(values) => validateForm(values, house, bookingFields)}
@@ -85,7 +90,8 @@ function FormCreator({ house, PortalSite }: Props): JSX.Element {
85
90
  arrival_date: values.arrivalDate.date,
86
91
  departure_date: values.departureDate.date,
87
92
  costs: JSON.stringify(values.costs),
88
- extra_fields: JSON.stringify(values.extra_fields)
93
+ extra_fields: JSON.stringify(values.extra_fields),
94
+ sessionIdentifier: sessionIdentifier
89
95
  };
90
96
 
91
97
  createBooking({ variables }).then(() => {
@@ -175,7 +181,7 @@ function FormCreator({ house, PortalSite }: Props): JSX.Element {
175
181
  <Summary house={house} values={values} />
176
182
  {status && status.msg && <div>{status.msg}</div>}
177
183
  <div className="terms">
178
- <FormattedMessage id="agree_with" />{' '}
184
+ {PortalSite.form_submit_text}{' '}
179
185
  <FormattedMessage id="terms">
180
186
  {(fm) => (
181
187
  <Modal buttonText={fm}>
@@ -212,7 +218,7 @@ function FormCreator({ house, PortalSite }: Props): JSX.Element {
212
218
  type="submit"
213
219
  disabled={isSubmitting}
214
220
  >
215
- <FormattedMessage id="book" />
221
+ {PortalSite.form_submit_button_text}
216
222
  </button>
217
223
  </div>
218
224
  </Form>
@@ -3,6 +3,7 @@ import Filters from './Filters';
3
3
  import Results from './Results';
4
4
  import { PortalOptions, PortalSiteType } from '../../types';
5
5
  import { FiltersType } from './filters/filter_types';
6
+ import { TrackEvent } from '../../_lib/Tracking';
6
7
 
7
8
  type MyProps = {
8
9
  options: PortalOptions;
@@ -71,7 +72,13 @@ class SearchPage extends Component<MyProps, MyState> {
71
72
 
72
73
  render() {
73
74
  const { filters, activePage, limit, skip } = this.state;
74
- const { options, PortalSite } = this.props;
75
+ const { options, PortalSite, locale } = this.props;
76
+
77
+ TrackEvent({
78
+ portal_code: PortalSite.portal_code,
79
+ interaction_type: 'search_view',
80
+ locale: locale
81
+ });
75
82
 
76
83
  return (
77
84
  <div