diff --git a/src/components/SEO/analytics.js b/src/components/SEO/analytics.js index 2df4a3ae..1bc75c4a 100644 --- a/src/components/SEO/analytics.js +++ b/src/components/SEO/analytics.js @@ -16,30 +16,32 @@ const attachScript = function (i, s, o, g, r, a, m) { /* eslint-enable */ export default (page, title) => { - if (!window.ga) { - attachScript( - window, - document, - 'script', - 'https://www.google-analytics.com/analytics.js', - 'ga' - ); + try { + if (!window.ga) { + attachScript( + window, + document, + 'script', + 'https://www.google-analytics.com/analytics.js', + 'ga' + ); - window.ga('create', 'UA-41619329-3', { cookieDomain: 'auto' }); - window.ga('require', 'linkid', 'linkid.js'); - } + window.ga('create', 'UA-41619329-3', { cookieDomain: 'auto' }); + window.ga('require', 'linkid', 'linkid.js'); + } - window.ga('send', 'pageview', { - page, - title, - }); - - if (!inIframe()) { - // start time on page tracking if not in an iframe - riveted.init({ - reportInterval: 30, + window.ga('send', 'pageview', { + page, + title, }); - } + + if (!inIframe()) { + // start time on page tracking if not in an iframe + riveted.init({ + reportInterval: 30, + }); + } + } catch (e) {} }; // checks if page is in an iframe diff --git a/src/components/SEO/publisherTags.js b/src/components/SEO/publisherTags.js index 83aabeb3..d01c092f 100644 --- a/src/components/SEO/publisherTags.js +++ b/src/components/SEO/publisherTags.js @@ -1,32 +1,34 @@ export default () => { - const { protocol } = document.location; - const gptScript = document.querySelector( - `script[src="${protocol}//www.googletagservices.com/tag/js/gpt.js"]` - ); - // Only do this once. - if (gptScript) return; - const googletag = window.googletag || {}; - googletag.cmd = googletag.cmd || []; - (function () { - const gads = document.createElement('script'); - gads.async = true; - gads.type = 'text/javascript'; - const useSSL = document.location.protocol === 'https:'; - gads.src = - (useSSL ? 'https:' : 'http:') + - '//www.googletagservices.com/tag/js/gpt.js'; - const node = document.getElementsByTagName('script')[0]; - node.parentNode.insertBefore(gads, node); - })(); - googletag.cmd.push(function () { - googletag - .defineSlot( - '/4735792/reuters_investigates', - [[300, 250]], - 'div-gpt-ad-1441822201033-0' - ) - .addService(googletag.pubads()); - googletag.pubads().enableSingleRequest(); - googletag.enableServices(); - }); + try { + const { protocol } = document.location; + const gptScript = document.querySelector( + `script[src="${protocol}//www.googletagservices.com/tag/js/gpt.js"]` + ); + // Only do this once. + if (gptScript) return; + const googletag = window.googletag || {}; + googletag.cmd = googletag.cmd || []; + (function () { + const gads = document.createElement('script'); + gads.async = true; + gads.type = 'text/javascript'; + const useSSL = document.location.protocol === 'https:'; + gads.src = + (useSSL ? 'https:' : 'http:') + + '//www.googletagservices.com/tag/js/gpt.js'; + const node = document.getElementsByTagName('script')[0]; + node.parentNode.insertBefore(gads, node); + })(); + googletag.cmd.push(function () { + googletag + .defineSlot( + '/4735792/reuters_investigates', + [[300, 250]], + 'div-gpt-ad-1441822201033-0' + ) + .addService(googletag.pubads()); + googletag.pubads().enableSingleRequest(); + googletag.enableServices(); + }); + } catch (e) {} };