bookito-widget 0.43.2 → 0.44.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.
package/package.json
CHANGED
|
@@ -8,6 +8,19 @@ import React from 'react';
|
|
|
8
8
|
// Once per page load per hotel, even with several widgets or modals on the page.
|
|
9
9
|
const trackedHotelIds = new Set<string>();
|
|
10
10
|
|
|
11
|
+
// GA page_location max. A longer URL is omitted so the load event still sends.
|
|
12
|
+
const MAX_PAGE_LOCATION_LENGTH = 1000;
|
|
13
|
+
|
|
14
|
+
export function hostingPageLocation(
|
|
15
|
+
location: { origin: string; pathname: string } = window.location
|
|
16
|
+
) {
|
|
17
|
+
// origin + pathname excludes location.search and location.hash.
|
|
18
|
+
const page = location.origin + location.pathname;
|
|
19
|
+
if (page.length > MAX_PAGE_LOCATION_LENGTH) return undefined;
|
|
20
|
+
if (!page.startsWith('https://') && !page.startsWith('http://')) return undefined;
|
|
21
|
+
return page;
|
|
22
|
+
}
|
|
23
|
+
|
|
11
24
|
const BookitoWidgetProvider: React.FC<{
|
|
12
25
|
language?: SupportedLocalesCode;
|
|
13
26
|
hotelId?: string;
|
|
@@ -16,7 +29,12 @@ const BookitoWidgetProvider: React.FC<{
|
|
|
16
29
|
React.useEffect(() => {
|
|
17
30
|
if (!props.hotelId || trackedHotelIds.has(props.hotelId)) return;
|
|
18
31
|
trackedHotelIds.add(props.hotelId);
|
|
19
|
-
|
|
32
|
+
const pageLocation = hostingPageLocation();
|
|
33
|
+
trackEvent({
|
|
34
|
+
event: 'web_widget_loaded',
|
|
35
|
+
hotelId: props.hotelId,
|
|
36
|
+
...(pageLocation ? { params: { page_location: pageLocation } } : {}),
|
|
37
|
+
});
|
|
20
38
|
}, [props.hotelId]);
|
|
21
39
|
|
|
22
40
|
return (
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { hostingPageLocation } from './BookitoWidgetProvider';
|
|
2
|
+
|
|
3
|
+
describe('hostingPageLocation', () => {
|
|
4
|
+
it('keeps scheme, host, and path', () => {
|
|
5
|
+
expect(
|
|
6
|
+
hostingPageLocation({
|
|
7
|
+
origin: 'https://www.lindenhof.it',
|
|
8
|
+
pathname: '/hotel-naturns/lindenhof-erlebnisse/',
|
|
9
|
+
})
|
|
10
|
+
).toBe('https://www.lindenhof.it/hotel-naturns/lindenhof-erlebnisse/');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('omits a non-http page and a url over 1000 characters', () => {
|
|
14
|
+
expect(hostingPageLocation({ origin: 'null', pathname: '/widget' })).toBeUndefined();
|
|
15
|
+
expect(
|
|
16
|
+
hostingPageLocation({
|
|
17
|
+
origin: 'https://www.lindenhof.it',
|
|
18
|
+
pathname: `/${'a'.repeat(1000)}`,
|
|
19
|
+
})
|
|
20
|
+
).toBeUndefined();
|
|
21
|
+
});
|
|
22
|
+
});
|