Skip to content

Commit

Permalink
fix: remove ga from index template
Browse files Browse the repository at this point in the history
  • Loading branch information
dsrkafuu committed Apr 2, 2021
1 parent d4c681b commit d947ad0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
11 changes: 0 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,6 @@
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />
<link rel="shortcut icon" href="/favicon.ico" />
<script async src="https://www.googletagmanager.com/gtag/js?id=G-WPCN48BP2Z"></script>
<script>
if (/dsrkafuu/.exec(location.hostname)) {
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-WPCN48BP2Z');
}
</script>
</head>
<body>
<div id="root"></div>
Expand Down
3 changes: 3 additions & 0 deletions src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import './themes';
import './scss/global.scss';
import './scss/utils.scss';

import ga from './plugins/ga';
ga();

import './i18n';
import App from './App';
import store from './store';
Expand Down
19 changes: 19 additions & 0 deletions src/plugins/ga.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const id = import.meta.env.VITE_GA;

export default function ga() {
function gtag() {
window.dataLayer.push(arguments);
}

if (id && import.meta.env.PROD) {
const script = document.createElement('script');
script.setAttribute('async', '');
script.setAttribute('src', `https://www.googletagmanager.com/gtag/js?id=${id}`);
document.head.appendChild(script);

window.dataLayer = window.dataLayer || [];
window.gtag = gtag;
gtag('js', new Date());
gtag('config', id);
}
}

1 comment on commit d947ad0

@vercel
Copy link

@vercel vercel bot commented on d947ad0 Apr 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.