@reykjavik/webtools 0.1.12 → 0.1.13
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/CHANGELOG.md +6 -0
- package/CookieHubConsent.d.ts +2 -2
- package/CookieHubConsent.js +2 -2
- package/README.md +63 -277
- package/esm/CookieHubConsent.d.ts +2 -2
- package/esm/CookieHubConsent.js +2 -2
- package/esm/fixIcelandicLocale.d.ts +1 -0
- package/esm/fixIcelandicLocale.js +21 -0
- package/esm/http.d.ts +3 -3
- package/esm/http.js +2 -2
- package/esm/index.d.ts +1 -0
- package/esm/next/SiteImprove.d.ts +4 -94
- package/esm/next/SiteImprove.js +12 -93
- package/esm/next/SiteImprove.privates.d.ts +100 -0
- package/esm/next/SiteImprove.privates.js +83 -0
- package/esm/next/http.d.ts +2 -2
- package/esm/next/http.js +3 -3
- package/esm/vanillaExtract.d.ts +5 -5
- package/esm/vanillaExtract.js +3 -3
- package/fixIcelandicLocale.d.ts +2 -0
- package/fixIcelandicLocale.js +21 -0
- package/http.d.ts +3 -3
- package/http.js +2 -2
- package/index.d.ts +1 -0
- package/next/SiteImprove.d.ts +4 -94
- package/next/SiteImprove.js +15 -96
- package/next/SiteImprove.privates.d.ts +100 -0
- package/next/SiteImprove.privates.js +91 -0
- package/next/http.d.ts +2 -2
- package/next/http.js +3 -3
- package/package.json +5 -1
- package/vanillaExtract.d.ts +5 -5
- package/vanillaExtract.js +3 -3
package/next/SiteImprove.d.ts
CHANGED
|
@@ -1,101 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
_sz?: Array<SiteImproveEvent> & {
|
|
6
|
-
/**
|
|
7
|
-
* Set if posting a tracking event is attempted before SiteImprove has
|
|
8
|
-
* been initialized, and the window._sz array had to be initialized
|
|
9
|
-
* just-in-time.
|
|
10
|
-
*/
|
|
11
|
-
_jit_defined_?: true;
|
|
12
|
-
core?: {
|
|
13
|
-
data: Array<SiteImproveEvent>;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
type SiteImproveEvent = SiteImprovePageView | SiteImproveRequest | SiteImproveCustomEvent;
|
|
19
|
-
type SiteImprovePageView = [
|
|
20
|
-
type: 'trackdynamic',
|
|
21
|
-
data: {
|
|
22
|
-
/** New page URL */
|
|
23
|
-
url: string;
|
|
24
|
-
/** The previous (referer) URL */
|
|
25
|
-
ref?: string;
|
|
26
|
-
/** New page title */
|
|
27
|
-
title?: string;
|
|
28
|
-
}
|
|
29
|
-
];
|
|
30
|
-
type SiteImproveRequest = [
|
|
31
|
-
type: 'request',
|
|
32
|
-
data: {
|
|
33
|
-
/** Outbound URL */
|
|
34
|
-
ourl: string;
|
|
35
|
-
/** The current page URL */
|
|
36
|
-
ref: string;
|
|
37
|
-
autoonclick?: 1;
|
|
38
|
-
}
|
|
39
|
-
];
|
|
40
|
-
type SiteImproveCustomEvent = [
|
|
41
|
-
type: 'event',
|
|
42
|
-
category: string,
|
|
43
|
-
action: string,
|
|
44
|
-
label?: string
|
|
45
|
-
];
|
|
46
|
-
/**
|
|
47
|
-
* A small helper for tracking custom UI events and reporting them to SiteImrove.
|
|
48
|
-
*
|
|
49
|
-
* @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimprove-helper
|
|
50
|
-
*/
|
|
51
|
-
export declare const pingSiteImprove: (category: string, action: string, label?: string) => void;
|
|
52
|
-
/**
|
|
53
|
-
* A small helper for reporting to SiteImrove when the user is programmatically
|
|
54
|
-
* being sent to a different URL/resource.
|
|
55
|
-
*
|
|
56
|
-
* @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimproveoutbound-helper
|
|
57
|
-
*/
|
|
58
|
-
export declare const pingSiteImproveOutbound: (ourl: string) => void;
|
|
59
|
-
export type SiteImproveProps = EitherObj<{
|
|
60
|
-
/**
|
|
61
|
-
* Your SiteImprove account ID.
|
|
62
|
-
*
|
|
63
|
-
* It's a random-looking numerical string, and it can usually be
|
|
64
|
-
* extracted from the script embed URL like this:
|
|
65
|
-
* `"https://siteimproveanalytics.com/js/siteanalyze_[ACCOUNT_ID].js"`
|
|
66
|
-
*/
|
|
67
|
-
accountId: string;
|
|
68
|
-
}, {
|
|
69
|
-
/**
|
|
70
|
-
* The full SiteImprove analytics script URL.
|
|
71
|
-
*
|
|
72
|
-
* Something like `"https://siteimproveanalytics.com/js/siteanalyze_[ACCOUNT_ID].js"`
|
|
73
|
-
*/
|
|
74
|
-
scriptUrl: string;
|
|
75
|
-
}> & {
|
|
76
|
-
/**
|
|
77
|
-
* Manual GDPR 'analytics' consent flag.
|
|
78
|
-
*
|
|
79
|
-
* A value of `false` prevents the analytics script being loaded.
|
|
80
|
-
*
|
|
81
|
-
* A value of `true` still defers to the 'analytics' consent state provided
|
|
82
|
-
* by the `CookieHubProvider` component (if present).
|
|
83
|
-
*/
|
|
84
|
-
hasConstented?: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Custom callback for when the SiteImprove script has loaded.
|
|
87
|
-
*/
|
|
88
|
-
onLoad?: (e: unknown) => void;
|
|
89
|
-
/**
|
|
90
|
-
* Error callback for if the SiteImprove script fails to load.
|
|
91
|
-
*/
|
|
92
|
-
onError?: (e: unknown) => void;
|
|
93
|
-
};
|
|
2
|
+
import { SiteImproveProps } from './SiteImprove.privates.js';
|
|
3
|
+
export type { SiteImproveProps } from './SiteImprove.privates.js';
|
|
4
|
+
export { pingSiteImprove, pingSiteImproveOutbound } from './SiteImprove.privates.js';
|
|
94
5
|
/**
|
|
95
6
|
* A component for loading a SiteImprove analytics script and set up page-view
|
|
96
7
|
* tracking across Next.js routes.
|
|
97
8
|
*
|
|
98
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
9
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README-nextjs.md#siteimprove-component
|
|
99
10
|
*/
|
|
100
11
|
export declare const SiteImprove: (props: SiteImproveProps) => React.JSX.Element | null;
|
|
101
|
-
export {};
|
package/next/SiteImprove.js
CHANGED
|
@@ -31,58 +31,13 @@ const react_1 = __importStar(require("react"));
|
|
|
31
31
|
const router_js_1 = require("next/router.js");
|
|
32
32
|
const script_js_1 = __importDefault(require("next/script.js"));
|
|
33
33
|
const CookieHubConsent_js_1 = require("../CookieHubConsent.js");
|
|
34
|
+
const SiteImprove_privates_js_1 = require("./SiteImprove.privates.js");
|
|
34
35
|
// Fixes an issue with `next/script`'s types and mixture of default and named exports.
|
|
35
36
|
// This workaround doesn't seem to be necessary in Next.js 13.5 (pages router), but
|
|
36
37
|
// is definitely needed for the webpack bundler used by Next.js 11. (v12 is untested.)
|
|
37
38
|
const Script = ('__esModule' in script_js_1.default && 'default' in script_js_1.default
|
|
38
39
|
? script_js_1.default.default
|
|
39
40
|
: script_js_1.default);
|
|
40
|
-
// END: Mock typing of SiteImprove's event tracking API
|
|
41
|
-
// --------------------------------------------------------------------------
|
|
42
|
-
//
|
|
43
|
-
// ---------------------------------------------------------------------------
|
|
44
|
-
const _emitEvent = typeof window === 'undefined'
|
|
45
|
-
? () => undefined
|
|
46
|
-
: (event) => {
|
|
47
|
-
let _sz = window._sz;
|
|
48
|
-
if (!_sz) {
|
|
49
|
-
_sz = window._sz = [];
|
|
50
|
-
_sz._jit_defined_ = true;
|
|
51
|
-
}
|
|
52
|
-
_sz.push(event);
|
|
53
|
-
if (process.env.NODE_ENV === 'development') {
|
|
54
|
-
console.info('SiteImprove:', event);
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
// ---------------------------------------------------------------------------
|
|
58
|
-
/**
|
|
59
|
-
* A small helper for tracking custom UI events and reporting them to SiteImrove.
|
|
60
|
-
*
|
|
61
|
-
* @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimprove-helper
|
|
62
|
-
*/
|
|
63
|
-
const pingSiteImprove = (category, action, label) => {
|
|
64
|
-
if (process.env.NODE_ENV === 'development' &&
|
|
65
|
-
(!window._sz || window._sz._jit_defined_)) {
|
|
66
|
-
console.warn('`pingSiteImprove` was called before SiteImprove script was loaded.');
|
|
67
|
-
}
|
|
68
|
-
_emitEvent(['event', category, action, label]);
|
|
69
|
-
};
|
|
70
|
-
exports.pingSiteImprove = pingSiteImprove;
|
|
71
|
-
// ---------------------------------------------------------------------------
|
|
72
|
-
/**
|
|
73
|
-
* A small helper for reporting to SiteImrove when the user is programmatically
|
|
74
|
-
* being sent to a different URL/resource.
|
|
75
|
-
*
|
|
76
|
-
* @see https://github.com/reykjavikcity/webtools/tree/v0.1##pingsiteimproveoutbound-helper
|
|
77
|
-
*/
|
|
78
|
-
const pingSiteImproveOutbound = (ourl) => {
|
|
79
|
-
if (process.env.NODE_ENV === 'development' &&
|
|
80
|
-
(!window._sz || window._sz._jit_defined_)) {
|
|
81
|
-
console.warn('`pingSiteImproveOutbound` was called before SiteImprove script was loaded.');
|
|
82
|
-
}
|
|
83
|
-
_emitEvent(['request', { ourl, ref: document.location.href }]);
|
|
84
|
-
};
|
|
85
|
-
exports.pingSiteImproveOutbound = pingSiteImproveOutbound;
|
|
86
41
|
// ---------------------------------------------------------------------------
|
|
87
42
|
/*
|
|
88
43
|
SiteImprove's "trackdynamic" (page view) event requires both the new URL
|
|
@@ -95,59 +50,25 @@ exports.pingSiteImproveOutbound = pingSiteImproveOutbound;
|
|
|
95
50
|
and it is thus safe to simply store the old URL in a local variable.
|
|
96
51
|
This may look dodgy, but should prove reasonably safe in practice.
|
|
97
52
|
*/
|
|
98
|
-
let
|
|
53
|
+
let _refUrl = '';
|
|
99
54
|
const captureRefUrl = () => {
|
|
100
|
-
|
|
55
|
+
_refUrl = document.location.pathname + document.location.search;
|
|
101
56
|
};
|
|
102
|
-
const sendRoutingEvent = (url) =>
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
// in that case we suppress the `ref`
|
|
109
|
-
ref: refUrl !== url ? refUrl : undefined,
|
|
110
|
-
title: document.title,
|
|
111
|
-
},
|
|
112
|
-
]);
|
|
113
|
-
// ---------------------------------------------------------------------------
|
|
114
|
-
const logOutboundLinks = () => {
|
|
115
|
-
const captureLinkClicks = (e) => {
|
|
116
|
-
const link = e.target.closest('a[href]');
|
|
117
|
-
if (!link || link.$$bound) {
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
link.$$bound = true;
|
|
121
|
-
// Waiting for the bubble phase allows other click handlers to preventDefault()
|
|
122
|
-
link.addEventListener('click', (e) => {
|
|
123
|
-
var _a, _b;
|
|
124
|
-
if (e.defaultPrevented) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
// Skip logging outbound request if SiteImprove has already done so.
|
|
128
|
-
// BTW, SiteImprove binds its autoonclick handlers on "mousedown"
|
|
129
|
-
// so they're guaranteed to have run before our "click" listener.
|
|
130
|
-
const events = (_b = (_a = window._sz) === null || _a === void 0 ? void 0 : _a.core) === null || _b === void 0 ? void 0 : _b.data;
|
|
131
|
-
const [type, data] = (events && events[events.length - 1]) || [];
|
|
132
|
-
if (type === 'request' && data.autoonclick && data.ourl === link.href) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
(0, exports.pingSiteImproveOutbound)(link.href);
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
const { body } = document;
|
|
139
|
-
// bind 'click' listener to the capture phase
|
|
140
|
-
body.addEventListener('click', captureLinkClicks, true);
|
|
141
|
-
return () => body.removeEventListener('click', captureLinkClicks, true);
|
|
57
|
+
const sendRoutingEvent = (url) => {
|
|
58
|
+
// On `history.back()`/`history.forward()` the URL change happens before
|
|
59
|
+
// `routeChangeStart`, so `refUrl` and `url` become the same.
|
|
60
|
+
// in that case we suppress the `ref`
|
|
61
|
+
const refUrl = _refUrl !== url ? _refUrl : undefined;
|
|
62
|
+
(0, SiteImprove_privates_js_1.trackDynamicPageView)(url, refUrl, document.title);
|
|
142
63
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
64
|
+
var SiteImprove_privates_js_2 = require("./SiteImprove.privates.js");
|
|
65
|
+
Object.defineProperty(exports, "pingSiteImprove", { enumerable: true, get: function () { return SiteImprove_privates_js_2.pingSiteImprove; } });
|
|
66
|
+
Object.defineProperty(exports, "pingSiteImproveOutbound", { enumerable: true, get: function () { return SiteImprove_privates_js_2.pingSiteImproveOutbound; } });
|
|
146
67
|
/**
|
|
147
68
|
* A component for loading a SiteImprove analytics script and set up page-view
|
|
148
69
|
* tracking across Next.js routes.
|
|
149
70
|
*
|
|
150
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
71
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README-nextjs.md#siteimprove-component
|
|
151
72
|
*/
|
|
152
73
|
const SiteImprove = (props) => {
|
|
153
74
|
const { analytics } = (0, CookieHubConsent_js_1.useCookieHubConsent)();
|
|
@@ -168,7 +89,7 @@ const SiteImprove = (props) => {
|
|
|
168
89
|
const routerEvents = router_js_1.Router.events;
|
|
169
90
|
routerEvents.on('routeChangeStart', captureRefUrl);
|
|
170
91
|
routerEvents.on('routeChangeComplete', sendRoutingEvent);
|
|
171
|
-
const stopLoggingOutboundLinks = logOutboundLinks();
|
|
92
|
+
const stopLoggingOutboundLinks = (0, SiteImprove_privates_js_1.logOutboundLinks)();
|
|
172
93
|
return () => {
|
|
173
94
|
routerEvents.off('routeChangeStart', captureRefUrl);
|
|
174
95
|
routerEvents.off('routeChangeComplete', sendRoutingEvent);
|
|
@@ -180,9 +101,7 @@ const SiteImprove = (props) => {
|
|
|
180
101
|
if (!consented || process.env.NODE_ENV !== 'production') {
|
|
181
102
|
return null;
|
|
182
103
|
}
|
|
183
|
-
const scriptUrl = props.scriptUrl != null
|
|
184
|
-
? props.scriptUrl
|
|
185
|
-
: scriptUrlTemplate.replace(idToken, props.accountId);
|
|
104
|
+
const scriptUrl = props.scriptUrl != null ? props.scriptUrl : (0, SiteImprove_privates_js_1.makeScriptUrl)(props.accountId);
|
|
186
105
|
return (react_1.default.createElement(Script, { type: "text/javascript", strategy: "afterInteractive", src: scriptUrl, onLoad: props.onLoad, onError: props.onError }));
|
|
187
106
|
};
|
|
188
107
|
exports.SiteImprove = SiteImprove;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { EitherObj } from '@reykjavik/hanna-utils';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
_sz?: Array<SiteImproveEvent> & {
|
|
5
|
+
/**
|
|
6
|
+
* Set if posting a tracking event is attempted before SiteImprove has
|
|
7
|
+
* been initialized, and the window._sz array had to be initialized
|
|
8
|
+
* just-in-time.
|
|
9
|
+
*/
|
|
10
|
+
_jit_defined_?: true;
|
|
11
|
+
core?: {
|
|
12
|
+
data: Array<SiteImproveEvent>;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export type SiteImproveEvent = SiteImprovePageView | SiteImproveRequest | SiteImproveCustomEvent;
|
|
18
|
+
export type SiteImprovePageView = [
|
|
19
|
+
type: 'trackdynamic',
|
|
20
|
+
data: {
|
|
21
|
+
/** New page URL */
|
|
22
|
+
url: string;
|
|
23
|
+
/** The previous (referer) URL */
|
|
24
|
+
ref?: string;
|
|
25
|
+
/** New page title */
|
|
26
|
+
title?: string;
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
export type SiteImproveRequest = [
|
|
30
|
+
type: 'request',
|
|
31
|
+
data: {
|
|
32
|
+
/** Outbound URL */
|
|
33
|
+
ourl: string;
|
|
34
|
+
/** The current page URL */
|
|
35
|
+
ref: string;
|
|
36
|
+
autoonclick?: 1;
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
export type SiteImproveCustomEvent = [
|
|
40
|
+
type: 'event',
|
|
41
|
+
category: string,
|
|
42
|
+
action: string,
|
|
43
|
+
label?: string
|
|
44
|
+
];
|
|
45
|
+
/**
|
|
46
|
+
* A small helper to send "trackdynamic" page view/load events to SiteImrove.
|
|
47
|
+
*
|
|
48
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README-nextjs.md#pingsiteimprove-helper
|
|
49
|
+
*/
|
|
50
|
+
export declare const trackDynamicPageView: (url: string, refUrl?: string, title?: string) => void;
|
|
51
|
+
/**
|
|
52
|
+
* A small helper for tracking custom UI events and reporting them to SiteImrove.
|
|
53
|
+
*
|
|
54
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README-nextjs.md#pingsiteimprove-helper
|
|
55
|
+
*/
|
|
56
|
+
export declare const pingSiteImprove: (category: string, action: string, label?: string) => void;
|
|
57
|
+
/**
|
|
58
|
+
* A small helper for reporting to SiteImrove when the user is programmatically
|
|
59
|
+
* being sent to a different URL/resource.
|
|
60
|
+
*
|
|
61
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README-nextjs.md#pingsiteimproveoutbound-helper
|
|
62
|
+
*/
|
|
63
|
+
export declare const pingSiteImproveOutbound: (ourl: string) => void;
|
|
64
|
+
export declare const logOutboundLinks: () => () => void;
|
|
65
|
+
export declare const makeScriptUrl: (accountId: string) => string;
|
|
66
|
+
export type SiteImproveProps = EitherObj<{
|
|
67
|
+
/**
|
|
68
|
+
* Your SiteImprove account ID.
|
|
69
|
+
*
|
|
70
|
+
* It's a random-looking numerical string, and it can usually be
|
|
71
|
+
* extracted from the script embed URL like this:
|
|
72
|
+
* `"https://siteimproveanalytics.com/js/siteanalyze_[ACCOUNT_ID].js"`
|
|
73
|
+
*/
|
|
74
|
+
accountId: string;
|
|
75
|
+
}, {
|
|
76
|
+
/**
|
|
77
|
+
* The full SiteImprove analytics script URL.
|
|
78
|
+
*
|
|
79
|
+
* Something like `"https://siteimproveanalytics.com/js/siteanalyze_[ACCOUNT_ID].js"`
|
|
80
|
+
*/
|
|
81
|
+
scriptUrl: string;
|
|
82
|
+
}> & {
|
|
83
|
+
/**
|
|
84
|
+
* Manual GDPR 'analytics' consent flag.
|
|
85
|
+
*
|
|
86
|
+
* A value of `false` prevents the analytics script being loaded.
|
|
87
|
+
*
|
|
88
|
+
* A value of `true` still defers to the 'analytics' consent state provided
|
|
89
|
+
* by the `CookieHubProvider` component (if present).
|
|
90
|
+
*/
|
|
91
|
+
hasConstented?: boolean;
|
|
92
|
+
/**
|
|
93
|
+
* Custom callback for when the SiteImprove script has loaded.
|
|
94
|
+
*/
|
|
95
|
+
onLoad?: (e: unknown) => void;
|
|
96
|
+
/**
|
|
97
|
+
* Error callback for if the SiteImprove script fails to load.
|
|
98
|
+
*/
|
|
99
|
+
onError?: (e: unknown) => void;
|
|
100
|
+
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeScriptUrl = exports.logOutboundLinks = exports.pingSiteImproveOutbound = exports.pingSiteImprove = exports.trackDynamicPageView = void 0;
|
|
4
|
+
// END: Mock typing of SiteImprove's event tracking API
|
|
5
|
+
// --------------------------------------------------------------------------
|
|
6
|
+
//
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
const _emitEvent = typeof window === 'undefined'
|
|
9
|
+
? () => undefined
|
|
10
|
+
: (event) => {
|
|
11
|
+
let _sz = window._sz;
|
|
12
|
+
if (!_sz) {
|
|
13
|
+
_sz = window._sz = [];
|
|
14
|
+
_sz._jit_defined_ = true;
|
|
15
|
+
}
|
|
16
|
+
_sz.push(event);
|
|
17
|
+
if (process.env.NODE_ENV === 'development') {
|
|
18
|
+
console.info('SiteImprove:', event);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
/**
|
|
23
|
+
* A small helper to send "trackdynamic" page view/load events to SiteImrove.
|
|
24
|
+
*
|
|
25
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README-nextjs.md#pingsiteimprove-helper
|
|
26
|
+
*/
|
|
27
|
+
const trackDynamicPageView = (url, refUrl, title) => _emitEvent(['trackdynamic', { url, ref: refUrl, title }]);
|
|
28
|
+
exports.trackDynamicPageView = trackDynamicPageView;
|
|
29
|
+
// ---------------------------------------------------------------------------
|
|
30
|
+
/**
|
|
31
|
+
* A small helper for tracking custom UI events and reporting them to SiteImrove.
|
|
32
|
+
*
|
|
33
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README-nextjs.md#pingsiteimprove-helper
|
|
34
|
+
*/
|
|
35
|
+
const pingSiteImprove = (category, action, label) => {
|
|
36
|
+
if (process.env.NODE_ENV === 'development' &&
|
|
37
|
+
(!window._sz || window._sz._jit_defined_)) {
|
|
38
|
+
console.warn('`pingSiteImprove` was called before SiteImprove script was loaded.');
|
|
39
|
+
}
|
|
40
|
+
_emitEvent(['event', category, action, label]);
|
|
41
|
+
};
|
|
42
|
+
exports.pingSiteImprove = pingSiteImprove;
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
/**
|
|
45
|
+
* A small helper for reporting to SiteImrove when the user is programmatically
|
|
46
|
+
* being sent to a different URL/resource.
|
|
47
|
+
*
|
|
48
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README-nextjs.md#pingsiteimproveoutbound-helper
|
|
49
|
+
*/
|
|
50
|
+
const pingSiteImproveOutbound = (ourl) => {
|
|
51
|
+
if (process.env.NODE_ENV === 'development' &&
|
|
52
|
+
(!window._sz || window._sz._jit_defined_)) {
|
|
53
|
+
console.warn('`pingSiteImproveOutbound` was called before SiteImprove script was loaded.');
|
|
54
|
+
}
|
|
55
|
+
_emitEvent(['request', { ourl, ref: document.location.href }]);
|
|
56
|
+
};
|
|
57
|
+
exports.pingSiteImproveOutbound = pingSiteImproveOutbound;
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
const logOutboundLinks = () => {
|
|
60
|
+
const captureLinkClicks = (e) => {
|
|
61
|
+
const link = e.target.closest('a[href]');
|
|
62
|
+
if (!link || link.$$bound) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
link.$$bound = true;
|
|
66
|
+
// Waiting for the bubble phase allows other click handlers to preventDefault()
|
|
67
|
+
link.addEventListener('click', (e) => {
|
|
68
|
+
var _a, _b;
|
|
69
|
+
if (e.defaultPrevented) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
// Skip logging outbound request if SiteImprove has already done so.
|
|
73
|
+
// BTW, SiteImprove binds its autoonclick handlers on "mousedown"
|
|
74
|
+
// so they're guaranteed to have run before our "click" listener.
|
|
75
|
+
const events = (_b = (_a = window._sz) === null || _a === void 0 ? void 0 : _a.core) === null || _b === void 0 ? void 0 : _b.data;
|
|
76
|
+
const [type, data] = (events && events[events.length - 1]) || [];
|
|
77
|
+
if (type === 'request' && data.autoonclick && data.ourl === link.href) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
(0, exports.pingSiteImproveOutbound)(link.href);
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
const { body } = document;
|
|
84
|
+
// bind 'click' listener to the capture phase
|
|
85
|
+
body.addEventListener('click', captureLinkClicks, true);
|
|
86
|
+
return () => body.removeEventListener('click', captureLinkClicks, true);
|
|
87
|
+
};
|
|
88
|
+
exports.logOutboundLinks = logOutboundLinks;
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
const makeScriptUrl = (accountId) => `https://siteimproveanalytics.com/js/siteanalyze_${accountId}.js`;
|
|
91
|
+
exports.makeScriptUrl = makeScriptUrl;
|
package/next/http.d.ts
CHANGED
|
@@ -26,7 +26,7 @@ export type InferErrorPageProps<SEP extends ShowErrorPageFn<any>> = Cleanup<Retu
|
|
|
26
26
|
* cases when `getServerSideProps` returns an `__error` prop with `statusCode`
|
|
27
27
|
* and optional friendly `message`.
|
|
28
28
|
*
|
|
29
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
29
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README-nextjs.md#makeerrorizeapphoc
|
|
30
30
|
*/
|
|
31
31
|
export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorPage: React.FunctionComponent<EP>) => {
|
|
32
32
|
<P extends {
|
|
@@ -48,7 +48,7 @@ export declare const makeErrorizeAppHOC: <EP extends Partial<ErrorProps>>(ErrorP
|
|
|
48
48
|
* to return an `HTTP_304_NotModified` response with an empty props object,
|
|
49
49
|
* in a way that doesn't make TypeScript shout at you.
|
|
50
50
|
*
|
|
51
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
51
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README-nextjs.md#notmodified304-helper
|
|
52
52
|
*/
|
|
53
53
|
export declare const notModified304: (response: ServerResponse | NextContextLike) => {
|
|
54
54
|
readonly props: any;
|
package/next/http.js
CHANGED
|
@@ -29,7 +29,7 @@ __exportStar(require("../http.js"), exports);
|
|
|
29
29
|
* Use this method inside a `getServerSideProps` method (or API route)
|
|
30
30
|
* to return an error page with proper HTTP status code and all the shit.
|
|
31
31
|
*
|
|
32
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
32
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README-nextjs.md#showerrorpage-helper
|
|
33
33
|
*/
|
|
34
34
|
const showErrorPage = (response, error, ttl = '2s') => {
|
|
35
35
|
error =
|
|
@@ -53,7 +53,7 @@ const showErrorPage = (response, error, ttl = '2s') => {
|
|
|
53
53
|
* cases when `getServerSideProps` returns an `__error` prop with `statusCode`
|
|
54
54
|
* and optional friendly `message`.
|
|
55
55
|
*
|
|
56
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
56
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README-nextjs.md#makeerrorizeapphoc
|
|
57
57
|
*/
|
|
58
58
|
const makeErrorizeAppHOC = (ErrorPage) => {
|
|
59
59
|
// the HOC
|
|
@@ -83,7 +83,7 @@ exports.makeErrorizeAppHOC = makeErrorizeAppHOC;
|
|
|
83
83
|
* to return an `HTTP_304_NotModified` response with an empty props object,
|
|
84
84
|
* in a way that doesn't make TypeScript shout at you.
|
|
85
85
|
*
|
|
86
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
86
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README-nextjs.md#notmodified304-helper
|
|
87
87
|
*/
|
|
88
88
|
const notModified304 = (response) => {
|
|
89
89
|
response = 'res' in response ? response.res : response;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reykjavik/webtools",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "Misc. JS/TS helpers used by Reykjavík City's web dev teams.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": "ssh://git@github.com:reykjavikcity/webtools.git",
|
|
@@ -50,6 +50,10 @@
|
|
|
50
50
|
"import": "./esm/http.js",
|
|
51
51
|
"require": "./http.js"
|
|
52
52
|
},
|
|
53
|
+
"./fixIcelandicLocale": {
|
|
54
|
+
"import": "./esm/fixIcelandicLocale.js",
|
|
55
|
+
"require": "./fixIcelandicLocale.js"
|
|
56
|
+
},
|
|
53
57
|
"./CookieHubConsent": {
|
|
54
58
|
"import": "./esm/CookieHubConsent.js",
|
|
55
59
|
"require": "./CookieHubConsent.js"
|
package/vanillaExtract.d.ts
CHANGED
|
@@ -2,20 +2,20 @@ import { GlobalStyleRule } from '@vanilla-extract/css';
|
|
|
2
2
|
/**
|
|
3
3
|
* Adds free-form CSS as a globalStyle
|
|
4
4
|
*
|
|
5
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
5
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaglobal
|
|
6
6
|
*/
|
|
7
7
|
export declare const vanillaGlobal: (css: string) => void;
|
|
8
8
|
/**
|
|
9
9
|
* Spreads the return value into a style object, to inject free-form CSS
|
|
10
10
|
* properties (or nested blocks)
|
|
11
11
|
*
|
|
12
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
12
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaprops
|
|
13
13
|
*/
|
|
14
14
|
export declare const vanillaProps: (css: string) => GlobalStyleRule;
|
|
15
15
|
/**
|
|
16
16
|
* Returns a scoped cssClassName styled with free-form CSS
|
|
17
17
|
*
|
|
18
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
18
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaclass
|
|
19
19
|
*/
|
|
20
20
|
export declare function vanillaClass(css: string): string;
|
|
21
21
|
export declare function vanillaClass(debugId: string, css: string): string;
|
|
@@ -28,7 +28,7 @@ export declare function vanillaClass(debugId: string, css: string): string;
|
|
|
28
28
|
* If you need something more sophisticated, use a custom `postcss` config.
|
|
29
29
|
*
|
|
30
30
|
*
|
|
31
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
31
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillanest
|
|
32
32
|
*/
|
|
33
33
|
export declare const vanillaNest: (ampSelector: string, css: string) => string;
|
|
34
34
|
/**
|
|
@@ -40,7 +40,7 @@ export declare const vanillaNest: (ampSelector: string, css: string) => string;
|
|
|
40
40
|
* NOTE: All "bare" (un-nested) style properties must come first,
|
|
41
41
|
* before any nested blocks.
|
|
42
42
|
*
|
|
43
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
43
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaclassnested
|
|
44
44
|
*/
|
|
45
45
|
export declare function vanillaClassNested(css: string): string;
|
|
46
46
|
export declare function vanillaClassNested(debugId: string, css: string): string;
|
package/vanillaExtract.js
CHANGED
|
@@ -5,7 +5,7 @@ const css_1 = require("@vanilla-extract/css");
|
|
|
5
5
|
/**
|
|
6
6
|
* Adds free-form CSS as a globalStyle
|
|
7
7
|
*
|
|
8
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
8
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaglobal
|
|
9
9
|
*/
|
|
10
10
|
const vanillaGlobal = (css) => (0, css_1.globalStyle)('x', { x: `} ${css} x{x:` });
|
|
11
11
|
exports.vanillaGlobal = vanillaGlobal;
|
|
@@ -14,7 +14,7 @@ exports.vanillaGlobal = vanillaGlobal;
|
|
|
14
14
|
* Spreads the return value into a style object, to inject free-form CSS
|
|
15
15
|
* properties (or nested blocks)
|
|
16
16
|
*
|
|
17
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
17
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillaprops
|
|
18
18
|
*/
|
|
19
19
|
const vanillaProps = (css) => ({ x: `; ${css}` });
|
|
20
20
|
exports.vanillaProps = vanillaProps;
|
|
@@ -34,7 +34,7 @@ exports.vanillaClass = vanillaClass;
|
|
|
34
34
|
* If you need something more sophisticated, use a custom `postcss` config.
|
|
35
35
|
*
|
|
36
36
|
*
|
|
37
|
-
* @see https://github.com/reykjavikcity/webtools/
|
|
37
|
+
* @see https://github.com/reykjavikcity/webtools/blob/v0.1/README.md#vanillanest
|
|
38
38
|
*/
|
|
39
39
|
const vanillaNest = (ampSelector, css) => css.replace(/&/g, ampSelector);
|
|
40
40
|
exports.vanillaNest = vanillaNest;
|