@reuters-graphics/graphics-components 0.0.28 → 0.0.29

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.
@@ -0,0 +1,2 @@
1
+ declare function _default(authors: any): void;
2
+ export default _default;
@@ -0,0 +1,3 @@
1
+ export { default as loadGA } from "./ga.js";
2
+ export { default as loadChartbeat } from "./chartbeat.js";
3
+ export { default as loadPublisherTags } from "./publisherTags.js";
@@ -1,6 +1,5 @@
1
1
  <!-- @component `SEO` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-SEO--default) -->
2
- <script>import analytics from './analytics';
3
- import publisherTags from './publisherTags';
2
+ <script>import { loadChartbeat, loadGA, loadPublisherTags, } from './analytics/index.js';
4
3
  /**
5
4
  * Base url for the page, which in [Vite-based projects](https://vitejs.dev/guide/build.html#public-base-path)
6
5
  * is globally available as `import.meta.env.BASE_URL`.
@@ -84,8 +83,9 @@ $: canonicalUrl = origin + pageUrl.pathname;
84
83
  // Only fire analytics on prod sites
85
84
  $: {
86
85
  if (typeof window !== 'undefined' && includeAnalytics) {
87
- analytics(canonicalUrl, seoTitle);
88
- publisherTags();
86
+ loadChartbeat(authors);
87
+ loadGA(canonicalUrl, seoTitle);
88
+ loadPublisherTags();
89
89
  }
90
90
  }
91
91
  const orgLdJson = {
@@ -0,0 +1,33 @@
1
+ /* eslint-disable */
2
+ const attachScript = () => {
3
+ // If script is already attached, skip
4
+ if (
5
+ document.querySelector(
6
+ 'script[src="//static.chartbeat.com/js/chartbeat.js"]'
7
+ )
8
+ )
9
+ return;
10
+ // ... else attach it.
11
+ const e = document.createElement('script');
12
+ const n = document.getElementsByTagName('script')[0];
13
+ e.type = 'text/javascript';
14
+ e.async = true;
15
+ e.src = '//static.chartbeat.com/js/chartbeat.js';
16
+ n.parentNode.insertBefore(e, n);
17
+ };
18
+
19
+ export default (authors) => {
20
+ // @ts-ignore
21
+ const _sf_async_config = (window._sf_async_config =
22
+ window._sf_async_config || {});
23
+ _sf_async_config.uid = 52639;
24
+ _sf_async_config.domain = 'reuters.com';
25
+ _sf_async_config.flickerControl = false;
26
+ _sf_async_config.useCanonical = true;
27
+ _sf_async_config.useCanonicalDomain = true;
28
+ _sf_async_config.sections = 'Graphics';
29
+ _sf_async_config.authors = authors.map((a) => a.name).join(',');
30
+ try {
31
+ attachScript();
32
+ } catch (e) {}
33
+ };
@@ -0,0 +1,40 @@
1
+ /* eslint-disable */
2
+ const attachScript = function (i, s, o, g, r, a, m) {
3
+ i.GoogleAnalyticsObject = r;
4
+ (i[r] =
5
+ i[r] ||
6
+ function () {
7
+ (i[r].q = i[r].q || []).push(arguments);
8
+ }),
9
+ (i[r].l = Date.now());
10
+ (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
11
+ a.async = 1;
12
+ a.src = g;
13
+ m.parentNode.insertBefore(a, m);
14
+ };
15
+ /* eslint-enable */
16
+
17
+ export default (page, title) => {
18
+ try {
19
+ // @ts-ignore
20
+ if (!window.ga) {
21
+ attachScript(
22
+ window,
23
+ document,
24
+ 'script',
25
+ 'https://www.google-analytics.com/analytics.js',
26
+ 'ga'
27
+ );
28
+
29
+ // @ts-ignore
30
+ window.ga('create', 'UA-41619329-3', { cookieDomain: 'auto' });
31
+ // @ts-ignore
32
+ window.ga('require', 'linkid', 'linkid.js');
33
+ }
34
+ // @ts-ignore
35
+ window.ga('send', 'pageview', {
36
+ page,
37
+ title,
38
+ });
39
+ } catch (e) {}
40
+ };
@@ -0,0 +1,3 @@
1
+ export { default as loadGA } from './ga.js';
2
+ export { default as loadChartbeat } from './chartbeat.js';
3
+ export { default as loadPublisherTags } from './publisherTags.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reuters-graphics/graphics-components",
3
- "version": "0.0.28",
3
+ "version": "0.0.29",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://reuters-graphics.github.io/graphics-components",
@@ -130,8 +130,10 @@
130
130
  "./components/ReutersGraphicsLogo/ReutersGraphicsLogo.svelte": "./dist/components/ReutersGraphicsLogo/ReutersGraphicsLogo.svelte",
131
131
  "./components/ReutersLogo/ReutersLogo.svelte": "./dist/components/ReutersLogo/ReutersLogo.svelte",
132
132
  "./components/SEO/SEO.svelte": "./dist/components/SEO/SEO.svelte",
133
- "./components/SEO/analytics": "./dist/components/SEO/analytics.js",
134
- "./components/SEO/publisherTags": "./dist/components/SEO/publisherTags.js",
133
+ "./components/SEO/analytics/chartbeat": "./dist/components/SEO/analytics/chartbeat.js",
134
+ "./components/SEO/analytics/ga": "./dist/components/SEO/analytics/ga.js",
135
+ "./components/SEO/analytics": "./dist/components/SEO/analytics/index.js",
136
+ "./components/SEO/analytics/publisherTags": "./dist/components/SEO/analytics/publisherTags.js",
135
137
  "./components/Scroller/Background.svelte": "./dist/components/Scroller/Background.svelte",
136
138
  "./components/Scroller/Embedded/Background.svelte": "./dist/components/Scroller/Embedded/Background.svelte",
137
139
  "./components/Scroller/Embedded/Foreground.svelte": "./dist/components/Scroller/Embedded/Foreground.svelte",
@@ -1,333 +0,0 @@
1
- // @ts-nocheck
2
- /* eslint-disable */
3
- const attachScript = function (i, s, o, g, r, a, m) {
4
- i.GoogleAnalyticsObject = r;
5
- (i[r] =
6
- i[r] ||
7
- function () {
8
- (i[r].q = i[r].q || []).push(arguments);
9
- }),
10
- (i[r].l = 1 * new Date());
11
- (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
12
- a.async = 1;
13
- a.src = g;
14
- m.parentNode.insertBefore(a, m);
15
- };
16
- /* eslint-enable */
17
-
18
- export default (page, title) => {
19
- try {
20
- if (!window.ga) {
21
- attachScript(
22
- window,
23
- document,
24
- 'script',
25
- 'https://www.google-analytics.com/analytics.js',
26
- 'ga'
27
- );
28
-
29
- window.ga('create', 'UA-41619329-3', { cookieDomain: 'auto' });
30
- window.ga('require', 'linkid', 'linkid.js');
31
- }
32
-
33
- window.ga('send', 'pageview', {
34
- page,
35
- title,
36
- });
37
-
38
- if (!inIframe()) {
39
- // start time on page tracking if not in an iframe
40
- riveted.init({
41
- reportInterval: 30,
42
- });
43
- }
44
- } catch (e) {}
45
- };
46
-
47
- // checks if page is in an iframe
48
- function inIframe() {
49
- try {
50
- return window.self !== window.top;
51
- } catch (e) {
52
- return true;
53
- }
54
- }
55
-
56
- /*
57
- * START: Riveted time on page tracking code
58
- * see aditional documentation here: https://riveted.parsnip.io/
59
- */
60
- /* eslint-disable */
61
- var riveted = (function () {
62
- let started = false;
63
- let stopped = false;
64
- let turnedOff = false;
65
- let clockTime = 0;
66
- const startTime = new Date();
67
- let clockTimer = null;
68
- let idleTimer = null;
69
- let sendEvent;
70
- let sendUserTiming;
71
- let reportInterval;
72
- let idleTimeout;
73
- let nonInteraction;
74
- let universalGA;
75
- let classicGA;
76
- let googleTagManager;
77
-
78
- function init(options) {
79
- /*
80
- * Determine which version of GA is being used
81
- * "ga", "_gaq", and "dataLayer" are the possible globals
82
- */
83
-
84
- if (typeof ga === 'function') {
85
- universalGA = true;
86
- }
87
-
88
- if (typeof _gaq !== 'undefined' && typeof _gaq.push === 'function') {
89
- classicGA = true;
90
- }
91
-
92
- if (
93
- typeof dataLayer !== 'undefined' &&
94
- typeof dataLayer.push === 'function'
95
- ) {
96
- googleTagManager = true;
97
- }
98
-
99
- // Set up options and defaults
100
- options = options || {};
101
- reportInterval = parseInt(options.reportInterval, 10) || 5;
102
- idleTimeout = parseInt(options.idleTimeout, 10) || 30;
103
-
104
- if (typeof options.eventHandler === 'function') {
105
- sendEvent = options.eventHandler;
106
- }
107
-
108
- if (typeof options.userTimingHandler === 'function') {
109
- sendUserTiming = options.userTimingHandler;
110
- }
111
-
112
- if (
113
- 'nonInteraction' in options &&
114
- (options.nonInteraction === false || options.nonInteraction === 'false')
115
- ) {
116
- nonInteraction = false;
117
- } else {
118
- nonInteraction = true;
119
- }
120
-
121
- // Basic activity event listeners
122
- addListener(document, 'keydown', trigger);
123
- addListener(document, 'click', trigger);
124
- addListener(window, 'mousemove', throttle(trigger, 500));
125
- addListener(window, 'scroll', throttle(trigger, 500));
126
-
127
- // Page visibility listeners
128
- addListener(document, 'visibilitychange', visibilityChange);
129
- addListener(document, 'webkitvisibilitychange', visibilityChange);
130
-
131
- // sends initial zero value
132
- sendEvent(0);
133
- }
134
-
135
- /*
136
- * Throttle function borrowed from:
137
- * Underscore.js 1.5.2
138
- * http://underscorejs.org
139
- * (c) 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
140
- * Underscore may be freely distributed under the MIT license.
141
- */
142
-
143
- function throttle(func, wait) {
144
- let context, args, result;
145
- let timeout = null;
146
- let previous = 0;
147
- const later = function () {
148
- previous = new Date();
149
- timeout = null;
150
- result = func.apply(context, args);
151
- };
152
- return function () {
153
- const now = new Date();
154
- if (!previous) previous = now;
155
- const remaining = wait - (now - previous);
156
- context = this;
157
- args = arguments;
158
- if (remaining <= 0) {
159
- clearTimeout(timeout);
160
- timeout = null;
161
- previous = now;
162
- result = func.apply(context, args);
163
- } else if (!timeout) {
164
- timeout = setTimeout(later, remaining);
165
- }
166
- return result;
167
- };
168
- }
169
-
170
- /*
171
- * Cross-browser event listening
172
- */
173
-
174
- function addListener(element, eventName, handler) {
175
- if (element.addEventListener) {
176
- element.addEventListener(eventName, handler, false);
177
- } else if (element.attachEvent) {
178
- element.attachEvent('on' + eventName, handler);
179
- } else {
180
- element['on' + eventName] = handler;
181
- }
182
- }
183
-
184
- /*
185
- * Function for logging User Timing event on initial interaction
186
- */
187
-
188
- sendUserTiming = function (timingValue) {
189
- if (googleTagManager) {
190
- dataLayer.push({
191
- event: 'RivetedTiming',
192
- eventCategory: 'Riveted',
193
- timingVar: 'First Interaction',
194
- timingValue,
195
- });
196
- } else {
197
- if (universalGA) {
198
- ga('send', 'timing', 'Riveted', 'First Interaction', timingValue);
199
- }
200
-
201
- if (classicGA) {
202
- _gaq.push([
203
- '_trackTiming',
204
- 'Riveted',
205
- 'First Interaction',
206
- timingValue,
207
- null,
208
- 100,
209
- ]);
210
- }
211
- }
212
- };
213
-
214
- /*
215
- * Function for logging ping events
216
- */
217
-
218
- sendEvent = function (time) {
219
- if (googleTagManager) {
220
- dataLayer.push({
221
- event: 'Riveted',
222
- eventCategory: 'Riveted',
223
- eventAction: 'Time Spent',
224
- eventLabel: time,
225
- eventValue: reportInterval,
226
- eventNonInteraction: nonInteraction,
227
- });
228
- } else {
229
- if (universalGA) {
230
- ga(
231
- 'send',
232
- 'event',
233
- 'Riveted',
234
- 'Time Spent',
235
- time.toString(),
236
- reportInterval,
237
- { nonInteraction }
238
- );
239
- }
240
-
241
- if (classicGA) {
242
- _gaq.push([
243
- '_trackEvent',
244
- 'Riveted',
245
- 'Time Spent',
246
- time.toString(),
247
- reportInterval,
248
- nonInteraction,
249
- ]);
250
- }
251
- }
252
- };
253
-
254
- function setIdle() {
255
- clearTimeout(idleTimer);
256
- stopClock();
257
- }
258
-
259
- function visibilityChange() {
260
- if (document.hidden || document.webkitHidden) {
261
- setIdle();
262
- }
263
- }
264
-
265
- function clock() {
266
- clockTime += 1;
267
- if (clockTime > 0 && clockTime % reportInterval === 0) {
268
- sendEvent(clockTime);
269
- }
270
- }
271
-
272
- function stopClock() {
273
- stopped = true;
274
- clearTimeout(clockTimer);
275
- }
276
-
277
- function turnOff() {
278
- setIdle();
279
- turnedOff = true;
280
- }
281
-
282
- function turnOn() {
283
- turnedOff = false;
284
- }
285
-
286
- function restartClock() {
287
- stopped = false;
288
- clearTimeout(clockTimer);
289
- clockTimer = setInterval(clock, 1000);
290
- }
291
-
292
- function startRiveted() {
293
- // Calculate seconds from start to first interaction
294
- const currentTime = new Date();
295
- const diff = currentTime - startTime;
296
-
297
- // Set global
298
- started = true;
299
-
300
- // Send User Timing Event
301
- sendUserTiming(diff);
302
-
303
- // Start clock
304
- clockTimer = setInterval(clock, 1000);
305
- }
306
-
307
- function trigger() {
308
- if (turnedOff) {
309
- return;
310
- }
311
-
312
- if (!started) {
313
- startRiveted();
314
- }
315
-
316
- if (stopped) {
317
- restartClock();
318
- }
319
-
320
- clearTimeout(idleTimer);
321
- idleTimer = setTimeout(setIdle, idleTimeout * 1000 + 100);
322
- }
323
-
324
- return {
325
- init,
326
- trigger,
327
- setIdle,
328
- on: turnOn,
329
- off: turnOff,
330
- };
331
- })();
332
- /* eslint-enable */
333
- /* END: Riveted time on page tracking code */