@reuters-graphics/graphics-components 0.0.28 → 0.0.30
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/dist/@types/components/@types/global.d.ts +1 -0
- package/dist/@types/components/SEO/analytics/chartbeat.d.ts +2 -0
- package/dist/@types/components/SEO/{analytics.d.ts → analytics/ga.d.ts} +0 -0
- package/dist/@types/components/SEO/analytics/index.d.ts +3 -0
- package/dist/@types/components/SEO/{publisherTags.d.ts → analytics/publisherTags.d.ts} +0 -0
- package/dist/@types/components/Scroller/Scroller.svelte.d.ts +2 -1
- package/dist/@types/components/Scroller/docProps.d.ts +2 -0
- package/dist/components/SEO/SEO.svelte +4 -4
- package/dist/components/SEO/analytics/chartbeat.js +33 -0
- package/dist/components/SEO/analytics/ga.js +40 -0
- package/dist/components/SEO/analytics/index.js +3 -0
- package/dist/components/SEO/{publisherTags.js → analytics/publisherTags.js} +0 -0
- package/dist/components/Scroller/Embedded/Background.svelte +2 -2
- package/dist/components/Scroller/Embedded/Foreground.svelte +26 -0
- package/dist/components/Scroller/Foreground.svelte +104 -1
- package/dist/components/Scroller/Scroller.svelte +3 -1
- package/dist/components/Scroller/docProps.js +1 -0
- package/package.json +5 -3
- package/dist/components/SEO/analytics.js +0 -333
|
File without changes
|
|
File without changes
|
|
@@ -11,9 +11,10 @@ declare const __propDef: {
|
|
|
11
11
|
*
|
|
12
12
|
* Each step object in the array can have:
|
|
13
13
|
*
|
|
14
|
-
* - `background` A background component **REQUIRED**
|
|
14
|
+
* - `background` A background component. **REQUIRED**
|
|
15
15
|
* - `backgroundProps` An object of props given to the background component
|
|
16
16
|
* - `foreground` Either a markdown-formatted string or a foreground component **REQUIRED**
|
|
17
|
+
* - `altText` A string describing the background graphic, which is read aloud after the foreground blurb. You can add it to each step or, if you want to add just one alt text to describe all graphics in the scroll section, add it to just the first step. **RECOMMENDED**
|
|
17
18
|
* - `foregroundProps` An object of props given to the foreground component
|
|
18
19
|
*
|
|
19
20
|
* @required
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ComponentType } from 'svelte';
|
|
2
2
|
interface BlockStep {
|
|
3
|
+
AltText?: string;
|
|
3
4
|
Background: string;
|
|
4
5
|
Text: string;
|
|
5
6
|
}
|
|
@@ -27,6 +28,7 @@ export declare const getScrollerPropsFromDoc: (docBlock: Block, aiCharts: AiChar
|
|
|
27
28
|
assetsPath: string;
|
|
28
29
|
};
|
|
29
30
|
foreground: string;
|
|
31
|
+
altText: string;
|
|
30
32
|
}[];
|
|
31
33
|
};
|
|
32
34
|
export {};
|
|
@@ -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
|
|
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
|
-
|
|
88
|
-
|
|
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
|
+
};
|
|
File without changes
|
|
@@ -4,8 +4,8 @@ export let index;
|
|
|
4
4
|
import Block from '../../Block/Block.svelte';
|
|
5
5
|
</script>
|
|
6
6
|
|
|
7
|
-
<Block width={backgroundWidth} cls="background-container step-{index + 1}">
|
|
8
|
-
<div class="embedded-background step-{index + 1}">
|
|
7
|
+
<Block width="{backgroundWidth}" cls="background-container step-{index + 1}">
|
|
8
|
+
<div class="embedded-background step-{index + 1}" aria-hidden="true">
|
|
9
9
|
<svelte:component
|
|
10
10
|
this="{step.background}"
|
|
11
11
|
{...step.backgroundProps || {}}
|
|
@@ -7,11 +7,23 @@ import Block from '../../Block/Block.svelte';
|
|
|
7
7
|
{#if step.foreground === '' || !step.foreground}
|
|
8
8
|
<!-- Empty foreground -->
|
|
9
9
|
<div class="empty-step-foreground step-{index + 1}"></div>
|
|
10
|
+
|
|
11
|
+
{#if typeof step.altText === 'string'}
|
|
12
|
+
<div class="background-alt-text visually-hidden">
|
|
13
|
+
{@html marked.parse(step.altText)}
|
|
14
|
+
</div>
|
|
15
|
+
{/if}
|
|
10
16
|
{:else if typeof step.foreground === 'string'}
|
|
11
17
|
<Block cls="body-text step-{index + 1}">
|
|
12
18
|
<div class="embedded-foreground step-{index + 1}">
|
|
13
19
|
{@html marked.parse(step.foreground)}
|
|
14
20
|
</div>
|
|
21
|
+
|
|
22
|
+
{#if typeof step.altText === 'string'}
|
|
23
|
+
<div class="background-alt-text visually-hidden">
|
|
24
|
+
{@html marked.parse(step.altText)}
|
|
25
|
+
</div>
|
|
26
|
+
{/if}
|
|
15
27
|
</Block>
|
|
16
28
|
{:else}
|
|
17
29
|
<div class="embedded-foreground step-{index + 1}">
|
|
@@ -200,4 +212,18 @@ div.embedded-foreground :global(.font-sans) {
|
|
|
200
212
|
}
|
|
201
213
|
div.embedded-foreground :global(p:last-child) {
|
|
202
214
|
margin-bottom: 0;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.visually-hidden {
|
|
218
|
+
position: absolute !important;
|
|
219
|
+
width: 1px !important;
|
|
220
|
+
height: 1px !important;
|
|
221
|
+
padding: 0 !important;
|
|
222
|
+
margin: -1px !important;
|
|
223
|
+
overflow: hidden !important;
|
|
224
|
+
clip: rect(0, 0, 0, 0) !important;
|
|
225
|
+
-webkit-clip-path: polygon(0px 0px, 0px 0px, 0px 0px);
|
|
226
|
+
clip-path: polygon(0px 0px, 0px 0px, 0px 0px);
|
|
227
|
+
white-space: nowrap !important;
|
|
228
|
+
border: 0 !important;
|
|
203
229
|
}</style>
|
|
@@ -7,6 +7,11 @@ import { marked } from 'marked';
|
|
|
7
7
|
{#if step.foreground === '' || !step.foreground}
|
|
8
8
|
<!-- Empty foreground -->
|
|
9
9
|
<div class="empty-step-foreground"></div>
|
|
10
|
+
{#if typeof step.altText === 'string'}
|
|
11
|
+
<div class="background-alt-text visually-hidden">
|
|
12
|
+
{@html marked.parse(step.altText)}
|
|
13
|
+
</div>
|
|
14
|
+
{/if}
|
|
10
15
|
{:else}
|
|
11
16
|
<div class="step-foreground">
|
|
12
17
|
{#if typeof step.foreground === 'string'}
|
|
@@ -18,11 +23,95 @@ import { marked } from 'marked';
|
|
|
18
23
|
/>
|
|
19
24
|
{/if}
|
|
20
25
|
</div>
|
|
26
|
+
{#if typeof step.altText === 'string'}
|
|
27
|
+
<div class="background-alt-text visually-hidden">
|
|
28
|
+
{@html marked.parse(step.altText)}
|
|
29
|
+
</div>
|
|
30
|
+
{/if}
|
|
21
31
|
{/if}
|
|
22
32
|
</div>
|
|
23
33
|
{/each}
|
|
24
34
|
|
|
25
|
-
<style
|
|
35
|
+
<style>.paragraph-size {
|
|
36
|
+
font-size: 1.3rem;
|
|
37
|
+
line-height: 2.1rem;
|
|
38
|
+
}
|
|
39
|
+
.paragraph-size.font-sans {
|
|
40
|
+
font-size: 1.1rem;
|
|
41
|
+
line-height: 1.75rem;
|
|
42
|
+
}
|
|
43
|
+
@media (max-width: 540px) {
|
|
44
|
+
.paragraph-size {
|
|
45
|
+
font-size: 1.1rem;
|
|
46
|
+
line-height: 1.8rem;
|
|
47
|
+
}
|
|
48
|
+
.paragraph-size.font-sans {
|
|
49
|
+
font-size: 1rem;
|
|
50
|
+
line-height: 1.6rem;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
.paragraph-size.important {
|
|
54
|
+
font-size: 1.3rem !important;
|
|
55
|
+
line-height: 2.1rem !important;
|
|
56
|
+
}
|
|
57
|
+
.paragraph-size.important.font-sans {
|
|
58
|
+
font-size: 1.1rem !important;
|
|
59
|
+
line-height: 1.8rem !important;
|
|
60
|
+
}
|
|
61
|
+
@media (max-width: 540px) {
|
|
62
|
+
.paragraph-size.important {
|
|
63
|
+
font-size: 1.1rem !important;
|
|
64
|
+
line-height: 1.8rem !important;
|
|
65
|
+
}
|
|
66
|
+
.paragraph-size.important.font-sans {
|
|
67
|
+
font-size: 1rem !important;
|
|
68
|
+
line-height: 1.6rem !important;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.small-size {
|
|
73
|
+
font-size: 0.9rem;
|
|
74
|
+
line-height: 1.2rem;
|
|
75
|
+
}
|
|
76
|
+
@media (max-width: 540px) {
|
|
77
|
+
.small-size {
|
|
78
|
+
font-size: 0.8rem;
|
|
79
|
+
line-height: 1.1rem;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
.small-size.important {
|
|
83
|
+
font-size: 0.9rem !important;
|
|
84
|
+
line-height: 1.2rem !important;
|
|
85
|
+
}
|
|
86
|
+
@media (max-width: 540px) {
|
|
87
|
+
.small-size.important {
|
|
88
|
+
font-size: 0.8rem !important;
|
|
89
|
+
line-height: 1.1rem !important;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.blockquote-size {
|
|
94
|
+
font-size: 1.6rem;
|
|
95
|
+
line-height: 2.1rem;
|
|
96
|
+
}
|
|
97
|
+
@media (max-width: 540px) {
|
|
98
|
+
.blockquote-size {
|
|
99
|
+
font-size: 1.3rem;
|
|
100
|
+
line-height: 1.9rem;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
.blockquote-size.important {
|
|
104
|
+
font-size: 1.6rem !important;
|
|
105
|
+
line-height: 2rem !important;
|
|
106
|
+
}
|
|
107
|
+
@media (max-width: 540px) {
|
|
108
|
+
.blockquote-size.important {
|
|
109
|
+
font-size: 1.3rem !important;
|
|
110
|
+
line-height: 1.8rem !important;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
div.step-foreground-container {
|
|
26
115
|
height: 100vh;
|
|
27
116
|
width: initial;
|
|
28
117
|
max-width: initial;
|
|
@@ -39,4 +128,18 @@ div.step-foreground-container .step-foreground {
|
|
|
39
128
|
}
|
|
40
129
|
div.step-foreground-container .step-foreground :global(p:last-child) {
|
|
41
130
|
margin-bottom: 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.visually-hidden {
|
|
134
|
+
position: absolute !important;
|
|
135
|
+
width: 1px !important;
|
|
136
|
+
height: 1px !important;
|
|
137
|
+
padding: 0 !important;
|
|
138
|
+
margin: -1px !important;
|
|
139
|
+
overflow: hidden !important;
|
|
140
|
+
clip: rect(0, 0, 0, 0) !important;
|
|
141
|
+
-webkit-clip-path: polygon(0px 0px, 0px 0px, 0px 0px);
|
|
142
|
+
clip-path: polygon(0px 0px, 0px 0px, 0px 0px);
|
|
143
|
+
white-space: nowrap !important;
|
|
144
|
+
border: 0 !important;
|
|
42
145
|
}</style>
|
|
@@ -9,9 +9,10 @@ export let id = '';
|
|
|
9
9
|
*
|
|
10
10
|
* Each step object in the array can have:
|
|
11
11
|
*
|
|
12
|
-
* - `background` A background component **REQUIRED**
|
|
12
|
+
* - `background` A background component. **REQUIRED**
|
|
13
13
|
* - `backgroundProps` An object of props given to the background component
|
|
14
14
|
* - `foreground` Either a markdown-formatted string or a foreground component **REQUIRED**
|
|
15
|
+
* - `altText` A string describing the background graphic, which is read aloud after the foreground blurb. You can add it to each step or, if you want to add just one alt text to describe all graphics in the scroll section, add it to just the first step. **RECOMMENDED**
|
|
15
16
|
* - `foregroundProps` An object of props given to the foreground component
|
|
16
17
|
*
|
|
17
18
|
* @required
|
|
@@ -99,6 +100,7 @@ let progress;
|
|
|
99
100
|
class="background"
|
|
100
101
|
class:right="{foregroundPosition === 'left opposite'}"
|
|
101
102
|
class:left="{foregroundPosition === 'right opposite'}"
|
|
103
|
+
aria-hidden="true"
|
|
102
104
|
>
|
|
103
105
|
<div class="scroller-graphic-well">
|
|
104
106
|
<Block
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reuters-graphics/graphics-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.30",
|
|
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/
|
|
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 */
|