@reuters-graphics/graphics-components 0.0.37 → 0.1.1

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,23 @@
1
+ import { SvelteComponentTyped } from "svelte";
2
+ /** Register virtual pageviews when using client-side routing in multipage applications. */
3
+ export declare function registerPageview(): void;
4
+ declare const __propDef: {
5
+ props: {
6
+ /**
7
+ * Used to associate a page with its author(s) in Chartbeat.
8
+ */ authors?: {
9
+ name: string;
10
+ }[];
11
+ };
12
+ events: {
13
+ [evt: string]: CustomEvent<any>;
14
+ };
15
+ slots: {};
16
+ };
17
+ export declare type AnalyticsProps = typeof __propDef.props;
18
+ export declare type AnalyticsEvents = typeof __propDef.events;
19
+ export declare type AnalyticsSlots = typeof __propDef.slots;
20
+ /** `Analytics` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-Analytics--default) */
21
+ export default class Analytics extends SvelteComponentTyped<AnalyticsProps, AnalyticsEvents, AnalyticsSlots> {
22
+ }
23
+ export {};
@@ -0,0 +1,5 @@
1
+ declare const _default: (authors: {
2
+ name: string;
3
+ }[]) => void;
4
+ export default _default;
5
+ export declare const registerPageview: () => void;
@@ -0,0 +1,3 @@
1
+ declare const _default: () => void;
2
+ export default _default;
3
+ export declare const registerPageview: () => void;
@@ -0,0 +1,2 @@
1
+ export { default as ga } from './ga';
2
+ export { default as chartbeat } from './chartbeat';
@@ -3,21 +3,21 @@
3
3
  /** @typedef {typeof __propDef.slots} IndexSlots */
4
4
  export default class Index extends SvelteComponentTyped<{
5
5
  [x: string]: any;
6
- value?: string;
7
- extract?: (item: {
8
- index: number;
9
- embed: string;
10
- }) => any;
11
- id?: string;
12
6
  data?: {
13
7
  index: number;
14
8
  embed: string;
15
9
  }[];
16
- disable?: (item: {
10
+ filter?: (item: {
17
11
  index: number;
18
12
  embed: string;
19
13
  }) => boolean;
20
- filter?: (item: {
14
+ value?: string;
15
+ extract?: (item: {
16
+ index: number;
17
+ embed: string;
18
+ }) => any;
19
+ id?: string;
20
+ disable?: (item: {
21
21
  index: number;
22
22
  embed: string;
23
23
  }) => boolean;
@@ -71,21 +71,21 @@ import { SvelteComponentTyped } from "svelte";
71
71
  declare const __propDef: {
72
72
  props: {
73
73
  [x: string]: any;
74
- value?: string;
75
- extract?: (item: {
76
- index: number;
77
- embed: string;
78
- }) => any;
79
- id?: string;
80
74
  data?: {
81
75
  index: number;
82
76
  embed: string;
83
77
  }[];
84
- disable?: (item: {
78
+ filter?: (item: {
85
79
  index: number;
86
80
  embed: string;
87
81
  }) => boolean;
88
- filter?: (item: {
82
+ value?: string;
83
+ extract?: (item: {
84
+ index: number;
85
+ embed: string;
86
+ }) => any;
87
+ id?: string;
88
+ disable?: (item: {
89
89
  index: number;
90
90
  embed: string;
91
91
  }) => boolean;
@@ -4,7 +4,7 @@ declare const __propDef: {
4
4
  /**
5
5
  * Base url for the page, which in [Vite-based projects](https://vitejs.dev/guide/build.html#public-base-path)
6
6
  * is globally available as `import.meta.env.BASE_URL`.
7
- * @required
7
+ * @requiredx
8
8
  * @type {string}
9
9
  */ baseUrl?: string;
10
10
  /**
@@ -55,9 +55,6 @@ declare const __propDef: {
55
55
  name: string;
56
56
  url: string;
57
57
  }[];
58
- /**
59
- * Whether to inject Google Analytics code for this page.
60
- */ includeAnalytics?: boolean;
61
58
  };
62
59
  events: {
63
60
  [evt: string]: CustomEvent<any>;
@@ -15,7 +15,7 @@ declare const __propDef: {
15
15
  /**
16
16
  * Preload options. `auto` is ignored if `autoplay` is true. Can also be `none` or `metadata`.
17
17
  * @type {string}
18
- */ preloadVideo?: "auto" | "metadata" | "none";
18
+ */ preloadVideo?: "metadata" | "auto" | "none";
19
19
  /**
20
20
  * Whether the video should loop.
21
21
  */ loopVideo?: boolean;
@@ -33,4 +33,5 @@ export { default as Video } from "./components/Video/Video.svelte";
33
33
  export { default as Visible } from "./components/Visible/Visible.svelte";
34
34
  export { getPhotoPackPropsFromDoc } from "./components/PhotoPack/docProps.js";
35
35
  export { getScrollerPropsFromDoc } from "./components/Scroller/docProps.js";
36
+ export { default as Analytics, registerPageview } from "./components/Analytics/Analytics.svelte";
36
37
  export { default as Theme, themes } from "./components/Theme/Theme.svelte";
@@ -0,0 +1,23 @@
1
+ <script context="module">
2
+ import { registerPageview as registerChartbeatPageview } from './providers/chartbeat';
3
+ import { registerPageview as registerGAPageview } from './providers/ga';
4
+
5
+ /** Register virtual pageviews when using client-side routing in multipage applications. */
6
+ export function registerPageview() {
7
+ registerChartbeatPageview();
8
+ registerGAPageview();
9
+ }
10
+ </script>
11
+
12
+ <!-- @component `Analytics` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-Analytics--default) -->
13
+ <script>/**
14
+ * Used to associate a page with its author(s) in Chartbeat.
15
+ */
16
+ export let authors = [];
17
+ import { onMount } from 'svelte';
18
+ import { ga, chartbeat } from './providers';
19
+ onMount(() => {
20
+ ga();
21
+ chartbeat(authors);
22
+ });
23
+ </script>
@@ -0,0 +1,41 @@
1
+ // Reuters Chartbeat UID
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
+ export default (authors) => {
17
+ window._sf_async_config = {
18
+ uid: UID,
19
+ domain: 'reuters.com',
20
+ flickerControl: false,
21
+ useCanonical: true,
22
+ useCanonicalDomain: true,
23
+ sections: 'Graphics',
24
+ authors: authors.map((a) => (a === null || a === void 0 ? void 0 : a.name) || '').join(','),
25
+ ...(window._sf_async_config || {}),
26
+ };
27
+ try {
28
+ attachScript();
29
+ }
30
+ catch (e) {
31
+ console.warn(`Error initialising Chartbeat Analytics: ${e}`);
32
+ }
33
+ };
34
+ export const registerPageview = () => {
35
+ if (typeof window === 'undefined' || !window.pSUPERFLY)
36
+ return;
37
+ window.pSUPERFLY({
38
+ path: window.location.pathname,
39
+ title: document === null || document === void 0 ? void 0 : document.title,
40
+ });
41
+ };
@@ -0,0 +1,44 @@
1
+ // Reuters Google Tag ID
2
+ const GOOGLE_TAG_ID = 'G-W3Q2X6NTNM';
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
+ export default () => {
17
+ try {
18
+ window.dataLayer = window.dataLayer || [];
19
+ if (!window.gtag) {
20
+ attachScript();
21
+ /** @type {Gtag.Gtag} */
22
+ window.gtag = function () {
23
+ window.dataLayer.push(arguments);
24
+ };
25
+ window.gtag('js', new Date());
26
+ // config event registers a pageview by default
27
+ window.gtag('config', GOOGLE_TAG_ID, {
28
+ send_page_view: false,
29
+ });
30
+ registerPageview();
31
+ }
32
+ }
33
+ catch (e) {
34
+ console.warn(`Error initialising Google Analytics: ${e}`);
35
+ }
36
+ };
37
+ export const registerPageview = () => {
38
+ if (typeof window === 'undefined' || !window.gtag)
39
+ return;
40
+ window.gtag('event', 'page_view', {
41
+ page_location: window.location.origin + window.location.pathname,
42
+ page_title: document === null || document === void 0 ? void 0 : document.title,
43
+ });
44
+ };
@@ -0,0 +1,2 @@
1
+ export { default as ga } from './ga';
2
+ export { default as chartbeat } from './chartbeat';
@@ -1,9 +1,8 @@
1
1
  <!-- @component `SEO` [Read the docs.](https://reuters-graphics.github.io/graphics-components/?path=/docs/components-SEO--default) -->
2
- <script>import { loadChartbeat, loadGA, loadPublisherTags, } from './analytics/index.js';
3
- /**
2
+ <script>/**
4
3
  * Base url for the page, which in [Vite-based projects](https://vitejs.dev/guide/build.html#public-base-path)
5
4
  * is globally available as `import.meta.env.BASE_URL`.
6
- * @required
5
+ * @requiredx
7
6
  * @type {string}
8
7
  */
9
8
  export let baseUrl = '';
@@ -62,10 +61,6 @@ export let updateTime = '';
62
61
  * Array of authors for the piece. Each author object must have `name` and `url` attributes.
63
62
  */
64
63
  export let authors = [];
65
- /**
66
- * Whether to inject Google Analytics code for this page.
67
- */
68
- export let includeAnalytics = false;
69
64
  const getOrigin = (baseUrl) => {
70
65
  try {
71
66
  return new URL(baseUrl).origin;
@@ -80,14 +75,6 @@ const getOrigin = (baseUrl) => {
80
75
  };
81
76
  $: origin = getOrigin(baseUrl);
82
77
  $: canonicalUrl = origin + pageUrl.pathname;
83
- // Only fire analytics on prod sites
84
- $: {
85
- if (typeof window !== 'undefined' && includeAnalytics) {
86
- loadChartbeat(authors);
87
- loadGA(canonicalUrl, seoTitle);
88
- loadPublisherTags();
89
- }
90
- }
91
78
  const orgLdJson = {
92
79
  '@context': 'http://schema.org',
93
80
  '@type': 'NewsMediaOrganization',
@@ -346,7 +346,7 @@ section.table table thead tr th {
346
346
  text-transform: uppercase;
347
347
  letter-spacing: 0.06rem;
348
348
  line-height: 1.4;
349
- padding: 0.5rem 0.25rem 0.5rem 0;
349
+ padding: 0.5rem 0.75rem 0.5rem 0;
350
350
  }
351
351
  section.table table thead tr th.sortable {
352
352
  cursor: pointer;
@@ -0,0 +1,23 @@
1
+ interface ChartbeatConfig {
2
+ uid?: number;
3
+ domain?: string;
4
+ flickerControl?: boolean;
5
+ useCanonical?: boolean;
6
+ useCanonicalDomain?: boolean;
7
+ sections?: string;
8
+ authors?: string;
9
+ }
10
+
11
+ declare global {
12
+ // eslint-disable-next-line no-unused-vars
13
+ interface Window {
14
+ /** Google analytics dataLayer */
15
+ dataLayer: Record<string, any>,
16
+ /** Chartbeat config */
17
+ _sf_async_config: ChartbeatConfig,
18
+ /** Chartbeat method */
19
+ pSUPERFLY: (config: { path: string, title: string }) => void,
20
+ }
21
+ }
22
+
23
+ export {};
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // Components
2
+ export { default as Analytics, registerPageview } from './components/Analytics/Analytics.svelte';
2
3
  export { default as Article } from './components/Article/Article.svelte';
3
4
  export { default as BeforeAfter } from './components/BeforeAfter/BeforeAfter.svelte';
4
5
  export { default as Block } from './components/Block/Block.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reuters-graphics/graphics-components",
3
- "version": "0.0.37",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://reuters-graphics.github.io/graphics-components",
@@ -41,6 +41,7 @@
41
41
  "@storybook/theming": "6.5.9",
42
42
  "@sveltejs/vite-plugin-svelte": "^1.0.1",
43
43
  "@tsconfig/svelte": "^3.0.0",
44
+ "@types/gtag.js": "^0.0.12",
44
45
  "@types/proper-url-join": "^2.1.1",
45
46
  "@types/react-syntax-highlighter": "^15.5.4",
46
47
  "@typescript-eslint/eslint-plugin": "^5.33.1",
@@ -100,6 +101,10 @@
100
101
  "./actions/cssVariables": "./dist/actions/cssVariables/index.js",
101
102
  "./actions/resizeObserver": "./dist/actions/resizeObserver/index.js",
102
103
  "./components/@types/global.ts": "./dist/components/@types/global.ts",
104
+ "./components/Analytics/Analytics.svelte": "./dist/components/Analytics/Analytics.svelte",
105
+ "./components/Analytics/providers/chartbeat.ts": "./dist/components/Analytics/providers/chartbeat.ts",
106
+ "./components/Analytics/providers/ga.ts": "./dist/components/Analytics/providers/ga.ts",
107
+ "./components/Analytics/providers/index.ts": "./dist/components/Analytics/providers/index.ts",
103
108
  "./components/Article/Article.svelte": "./dist/components/Article/Article.svelte",
104
109
  "./components/BeforeAfter/BeforeAfter.svelte": "./dist/components/BeforeAfter/BeforeAfter.svelte",
105
110
  "./components/Block/Block.svelte": "./dist/components/Block/Block.svelte",
@@ -131,10 +136,6 @@
131
136
  "./components/ReutersGraphicsLogo/ReutersGraphicsLogo.svelte": "./dist/components/ReutersGraphicsLogo/ReutersGraphicsLogo.svelte",
132
137
  "./components/ReutersLogo/ReutersLogo.svelte": "./dist/components/ReutersLogo/ReutersLogo.svelte",
133
138
  "./components/SEO/SEO.svelte": "./dist/components/SEO/SEO.svelte",
134
- "./components/SEO/analytics/chartbeat": "./dist/components/SEO/analytics/chartbeat.js",
135
- "./components/SEO/analytics/ga": "./dist/components/SEO/analytics/ga.js",
136
- "./components/SEO/analytics": "./dist/components/SEO/analytics/index.js",
137
- "./components/SEO/analytics/publisherTags": "./dist/components/SEO/analytics/publisherTags.js",
138
139
  "./components/Scroller/Background.svelte": "./dist/components/Scroller/Background.svelte",
139
140
  "./components/Scroller/Embedded/Background.svelte": "./dist/components/Scroller/Embedded/Background.svelte",
140
141
  "./components/Scroller/Embedded/Foreground.svelte": "./dist/components/Scroller/Embedded/Foreground.svelte",
@@ -206,6 +207,7 @@
206
207
  "./components/Video/Controls.svelte": "./dist/components/Video/Controls.svelte",
207
208
  "./components/Video/Video.svelte": "./dist/components/Video/Video.svelte",
208
209
  "./components/Visible/Visible.svelte": "./dist/components/Visible/Visible.svelte",
210
+ "./globals.d.ts": "./dist/globals.d.ts",
209
211
  "./scss/mixins": "./dist/scss/_mixins.scss",
210
212
  "./scss/variables": "./dist/scss/_variables.scss",
211
213
  "./scss/bootstrap/main": "./dist/scss/bootstrap/_main.scss",
@@ -1,2 +0,0 @@
1
- declare function _default(authors: any): void;
2
- export default _default;
@@ -1,2 +0,0 @@
1
- declare function _default(page: any, title: any): void;
2
- export default _default;
@@ -1,3 +0,0 @@
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,2 +0,0 @@
1
- declare function _default(): void;
2
- export default _default;
@@ -1,33 +0,0 @@
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
- };
@@ -1,40 +0,0 @@
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
- };
@@ -1,3 +0,0 @@
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,34 +0,0 @@
1
- export default () => {
2
- try {
3
- const { protocol } = document.location;
4
- const gptScript = document.querySelector(
5
- `script[src="${protocol}//www.googletagservices.com/tag/js/gpt.js"]`
6
- );
7
- // Only do this once.
8
- if (gptScript) return;
9
- const googletag = window.googletag || {};
10
- googletag.cmd = googletag.cmd || [];
11
- (function () {
12
- const gads = document.createElement('script');
13
- gads.async = true;
14
- gads.type = 'text/javascript';
15
- const useSSL = document.location.protocol === 'https:';
16
- gads.src =
17
- (useSSL ? 'https:' : 'http:') +
18
- '//www.googletagservices.com/tag/js/gpt.js';
19
- const node = document.getElementsByTagName('script')[0];
20
- node.parentNode.insertBefore(gads, node);
21
- })();
22
- googletag.cmd.push(function () {
23
- googletag
24
- .defineSlot(
25
- '/4735792/reuters_investigates',
26
- [[300, 250]],
27
- 'div-gpt-ad-1441822201033-0'
28
- )
29
- .addService(googletag.pubads());
30
- googletag.pubads().enableSingleRequest();
31
- googletag.enableServices();
32
- });
33
- } catch (e) {}
34
- };