Do not send analytics for dev mode
This commit is contained in:
@ -1,3 +1,4 @@
|
|||||||
|
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants');
|
||||||
import NextHead from 'next/head';
|
import NextHead from 'next/head';
|
||||||
import siteConfig from 'storage/site';
|
import siteConfig from 'storage/site';
|
||||||
import { GA_TRACKING_ID } from 'lib/gtag';
|
import { GA_TRACKING_ID } from 'lib/gtag';
|
||||||
@ -22,13 +23,13 @@ const Helmet = (props) => (
|
|||||||
<meta name="keywords" content={ siteConfig.keywords.join(',') } />
|
<meta name="keywords" content={ siteConfig.keywords.join(',') } />
|
||||||
|
|
||||||
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0, maximum-scale=3.0, minimum-scale=1.0" />
|
<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=1.0, maximum-scale=3.0, minimum-scale=1.0" />
|
||||||
<link rel="canonical" href={ siteConfig.url.web } />
|
<link rel="canonical" href={ siteConfig.url } />
|
||||||
<meta httpEquiv="Content-Language" content="en" />
|
<meta httpEquiv="Content-Language" content="en" />
|
||||||
|
|
||||||
<meta property="og:title" content={ prepareTitle(props.title) } />
|
<meta property="og:title" content={ prepareTitle(props.title) } />
|
||||||
<meta property="og:description" content={ prepareDescription(props.description) } />
|
<meta property="og:description" content={ prepareDescription(props.description) } />
|
||||||
<meta property="og:image" content={ siteConfig.logo } />
|
<meta property="og:image" content={ siteConfig.logo } />
|
||||||
<meta property="og:url" content={ siteConfig.url.web } />
|
<meta property="og:url" content={ siteConfig.url } />
|
||||||
<meta property="og:type" content="website" />
|
<meta property="og:type" content="website" />
|
||||||
<meta property="article:publisher" content={ `https://facebook.com/${siteConfig.facebook}` } />
|
<meta property="article:publisher" content={ `https://facebook.com/${siteConfig.facebook}` } />
|
||||||
<meta property="og:site_name" content={ siteConfig.name } />
|
<meta property="og:site_name" content={ siteConfig.name } />
|
||||||
@ -55,15 +56,19 @@ const Helmet = (props) => (
|
|||||||
<link rel="icon" href="/static/manifest/favicon.ico" type="image/x-icon" />
|
<link rel="icon" href="/static/manifest/favicon.ico" type="image/x-icon" />
|
||||||
|
|
||||||
{ /* Global Site Tag (gtag.js) - Google Analytics */ }
|
{ /* Global Site Tag (gtag.js) - Google Analytics */ }
|
||||||
<script async src={ `https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}` } />
|
{ !PHASE_DEVELOPMENT_SERVER && (
|
||||||
<script dangerouslySetInnerHTML={{
|
<>
|
||||||
__html: `
|
<script async src={ `https://www.googletagmanager.com/gtag/js?id=${GA_TRACKING_ID}` } />
|
||||||
window.dataLayer = window.dataLayer || [];
|
<script dangerouslySetInnerHTML={{
|
||||||
function gtag(){dataLayer.push(arguments);}
|
__html: `
|
||||||
gtag('js', new Date());
|
window.dataLayer = window.dataLayer || [];
|
||||||
gtag('config', '${GA_TRACKING_ID}');
|
function gtag(){dataLayer.push(arguments);}
|
||||||
`,
|
gtag('js', new Date());
|
||||||
}} />
|
gtag('config', '${GA_TRACKING_ID}');
|
||||||
|
`,
|
||||||
|
}} />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</NextHead>
|
</NextHead>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
10
lib/gtag.js
10
lib/gtag.js
@ -2,6 +2,11 @@ export const GA_TRACKING_ID = 'UA-139582634-1';
|
|||||||
|
|
||||||
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
// https://developers.google.com/analytics/devguides/collection/gtagjs/pages
|
||||||
export const firePageView = url => {
|
export const firePageView = url => {
|
||||||
|
if (!window.gtag) {
|
||||||
|
console.warn('Missing GTAG – Analytics disabled');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
window.gtag('config', GA_TRACKING_ID, {
|
window.gtag('config', GA_TRACKING_ID, {
|
||||||
page_path: url,
|
page_path: url,
|
||||||
})
|
})
|
||||||
@ -9,6 +14,11 @@ export const firePageView = url => {
|
|||||||
|
|
||||||
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
|
// https://developers.google.com/analytics/devguides/collection/gtagjs/events
|
||||||
export const event = ({ action, category, label, value }) => {
|
export const event = ({ action, category, label, value }) => {
|
||||||
|
if (!window.gtag) {
|
||||||
|
console.warn('Missing GTAG – Analytics disabled');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
window.gtag('event', action, {
|
window.gtag('event', action, {
|
||||||
event_category: category,
|
event_category: category,
|
||||||
event_label: label,
|
event_label: label,
|
||||||
|
Reference in New Issue
Block a user