@reuters-graphics/graphics-components 3.0.15 → 3.0.17
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.
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
<!-- @component `Analytics` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-ads-analytics-analytics--docs) -->
|
|
2
2
|
|
|
3
3
|
<script module>
|
|
4
|
+
// GTM configuration
|
|
5
|
+
const GTM_ID = 'GTM-P9TTSWG2';
|
|
6
|
+
const GTM_SCRIPT = `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','${GTM_ID}');`;
|
|
7
|
+
|
|
4
8
|
import { registerPageview as registerChartbeatPageview } from './providers/chartbeat';
|
|
5
9
|
import { registerPageview as registerGAPageview } from './providers/ga';
|
|
6
10
|
|
|
@@ -34,3 +38,21 @@
|
|
|
34
38
|
chartbeat(authors);
|
|
35
39
|
});
|
|
36
40
|
</script>
|
|
41
|
+
|
|
42
|
+
<svelte:head>
|
|
43
|
+
<!-- Google Tag Manager -->
|
|
44
|
+
{@html `<${'script'}>${GTM_SCRIPT}</script>`}
|
|
45
|
+
<!-- End Google Tag Manager -->
|
|
46
|
+
</svelte:head>
|
|
47
|
+
|
|
48
|
+
<!-- Google Tag Manager (noscript) -->
|
|
49
|
+
<noscript>
|
|
50
|
+
<iframe
|
|
51
|
+
src="https://www.googletagmanager.com/ns.html?id={GTM_ID}"
|
|
52
|
+
height="0"
|
|
53
|
+
width="0"
|
|
54
|
+
style="display:none;visibility:hidden"
|
|
55
|
+
title=""
|
|
56
|
+
></iframe>
|
|
57
|
+
</noscript>
|
|
58
|
+
<!-- End Google Tag Manager (noscript) -->
|
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
// Reuters Chartbeat UID
|
|
2
2
|
const UID = 52639;
|
|
3
|
-
const URL = '//static.chartbeat.com/js/chartbeat.js';
|
|
4
|
-
const attachScript = () => {
|
|
5
|
-
// If script is already attached, skip
|
|
6
|
-
if (document.querySelector(`script[src="${URL}"]`))
|
|
7
|
-
return;
|
|
8
|
-
// ... else attach it.
|
|
9
|
-
const e = document.createElement('script');
|
|
10
|
-
const n = document.getElementsByTagName('script')[0];
|
|
11
|
-
e.type = 'text/javascript';
|
|
12
|
-
e.async = true;
|
|
13
|
-
e.src = URL;
|
|
14
|
-
n.parentNode.insertBefore(e, n);
|
|
15
|
-
};
|
|
16
3
|
export default (authors) => {
|
|
17
4
|
window._sf_async_config = {
|
|
18
5
|
uid: UID,
|
|
@@ -24,12 +11,6 @@ export default (authors) => {
|
|
|
24
11
|
authors: authors.map((a) => a?.name || '').join(','),
|
|
25
12
|
...(window._sf_async_config || {}),
|
|
26
13
|
};
|
|
27
|
-
try {
|
|
28
|
-
attachScript();
|
|
29
|
-
}
|
|
30
|
-
catch (e) {
|
|
31
|
-
console.warn(`Error initialising Chartbeat Analytics: ${e}`);
|
|
32
|
-
}
|
|
33
14
|
};
|
|
34
15
|
export const registerPageview = () => {
|
|
35
16
|
if (typeof window === 'undefined' || !window.pSUPERFLY)
|
|
@@ -1,23 +1,9 @@
|
|
|
1
1
|
// Reuters Google Tag ID
|
|
2
2
|
const GOOGLE_TAG_ID = 'G-WBSR7WLTGD';
|
|
3
|
-
const URL = `https://www.googletagmanager.com/gtag/js?id=${GOOGLE_TAG_ID}`;
|
|
4
|
-
const attachScript = () => {
|
|
5
|
-
// If script is already attached, skip
|
|
6
|
-
if (document.querySelector(`script[src="${URL}"]`))
|
|
7
|
-
return;
|
|
8
|
-
// ... else attach it.
|
|
9
|
-
const e = document.createElement('script');
|
|
10
|
-
const n = document.getElementsByTagName('script')[0];
|
|
11
|
-
e.type = 'text/javascript';
|
|
12
|
-
e.async = true;
|
|
13
|
-
e.src = URL;
|
|
14
|
-
n.parentNode.insertBefore(e, n);
|
|
15
|
-
};
|
|
16
3
|
export default () => {
|
|
17
4
|
try {
|
|
18
5
|
window.dataLayer = window.dataLayer || [];
|
|
19
6
|
if (!window.gtag) {
|
|
20
|
-
attachScript();
|
|
21
7
|
/** @type {Gtag.Gtag} */
|
|
22
8
|
window.gtag = function () {
|
|
23
9
|
// eslint-disable-next-line prefer-rest-params
|
package/dist/test/utils.test.js
CHANGED
|
@@ -88,6 +88,15 @@ describe('Utils tests', () => {
|
|
|
88
88
|
const unformattedSept = 'Sep. 2025';
|
|
89
89
|
const formattedSept = 'Sept. 2025';
|
|
90
90
|
expect(prettifyDate(unformattedSept)).toBe(formattedSept);
|
|
91
|
+
const unformattedOct = 'Oct. 2025';
|
|
92
|
+
const formattedOct = 'Oct. 2025';
|
|
93
|
+
expect(prettifyDate(unformattedOct)).toBe(formattedOct);
|
|
94
|
+
const unformattedNov = 'Nov 2025';
|
|
95
|
+
const formattedNov = 'Nov. 2025';
|
|
96
|
+
expect(prettifyDate(unformattedNov)).toBe(formattedNov);
|
|
97
|
+
const unformattedDec = 'DEC 2025';
|
|
98
|
+
const formattedDec = 'Dec. 2025';
|
|
99
|
+
expect(prettifyDate(unformattedDec)).toBe(formattedDec);
|
|
91
100
|
});
|
|
92
101
|
it('should fix spacing between time and am/pm', () => {
|
|
93
102
|
const unformattedMarch = 'Mar. 1, 2023, 10:00pm';
|
|
@@ -102,9 +111,15 @@ describe('Utils tests', () => {
|
|
|
102
111
|
const unformattedJune = 'Jun. 1, 2023, 10:00AM';
|
|
103
112
|
const formattedJune = 'June 1, 2023, 10:00 a.m.';
|
|
104
113
|
expect(prettifyDate(unformattedJune)).toBe(formattedJune);
|
|
114
|
+
const unformattedAug = 'aug 1, 2023, 10:00PM';
|
|
115
|
+
const formattedAug = 'Aug. 1, 2023, 10:00 p.m.';
|
|
116
|
+
expect(prettifyDate(unformattedAug)).toBe(formattedAug);
|
|
105
117
|
const unformattedSept = 'sep. 1, 2023, 10:00PM';
|
|
106
118
|
const formattedSept = 'Sept. 1, 2023, 10:00 p.m.';
|
|
107
119
|
expect(prettifyDate(unformattedSept)).toBe(formattedSept);
|
|
120
|
+
const unformattedOct = 'oct 1, 2023, 10:00PM';
|
|
121
|
+
const formattedOct = 'Oct. 1, 2023, 10:00 p.m.';
|
|
122
|
+
expect(prettifyDate(unformattedOct)).toBe(formattedOct);
|
|
108
123
|
});
|
|
109
124
|
it('should work with lower or upper case', () => {
|
|
110
125
|
const unformattedMarch = 'MAR. 1, 2023, 10:00pm';
|
|
@@ -119,5 +134,8 @@ describe('Utils tests', () => {
|
|
|
119
134
|
const unformattedJune = 'JUN. 1, 2023, 10:00AM';
|
|
120
135
|
const formattedJune = 'June 1, 2023, 10:00 a.m.';
|
|
121
136
|
expect(prettifyDate(unformattedJune)).toBe(formattedJune);
|
|
137
|
+
const unformattedAug = 'AUG. 1, 2023, 10:00PM';
|
|
138
|
+
const formattedAug = 'Aug. 1, 2023, 10:00 p.m.';
|
|
139
|
+
expect(prettifyDate(unformattedAug)).toBe(formattedAug);
|
|
122
140
|
});
|
|
123
141
|
});
|
package/dist/utils/index.js
CHANGED
|
@@ -47,7 +47,11 @@ export const prettifyDate = (input) => {
|
|
|
47
47
|
apr: 'April',
|
|
48
48
|
jun: 'June',
|
|
49
49
|
jul: 'July',
|
|
50
|
+
aug: 'Aug.',
|
|
50
51
|
sep: 'Sept.',
|
|
52
|
+
oct: 'Oct.',
|
|
53
|
+
nov: 'Nov.',
|
|
54
|
+
dec: 'Dec.',
|
|
51
55
|
};
|
|
52
56
|
// If the key in conversions is found in the input (case insensitive), replace it with the corresponding value
|
|
53
57
|
const formatted = Object.keys(conversions).reduce((acc, key) => {
|