try catch analytics stuff

This commit is contained in:
Jon McClure 2022-11-18 18:20:43 +00:00
parent 53ab2038b2
commit 54c7b809b9
2 changed files with 55 additions and 51 deletions

View file

@ -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

View file

@ -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) {}
};