📈 site: fix ga event

This commit is contained in:
afc163 2018-11-13 15:24:12 +08:00
parent b9f8e1a058
commit c1908e78e5
3 changed files with 12 additions and 12 deletions

View File

@ -113,7 +113,6 @@
"cross-env": "^5.2.0",
"css-split-webpack-plugin": "^0.2.6",
"dekko": "^0.2.1",
"delegate": "^3.2.0",
"docsearch.js": "^2.5.2",
"enquire-js": "^0.2.1",
"enzyme": "^3.7.0",

View File

@ -80,7 +80,7 @@
</div>
<script src="{{ root }}common.js"></script>
<script src="{{ root }}index.js"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-72788897-1"></script>
<script>
if (!location.port) {

View File

@ -4,7 +4,6 @@ import { FormattedMessage } from 'react-intl';
import DocumentTitle from 'react-document-title';
import { getChildren } from 'jsonml.js/lib/utils';
import { Timeline, Alert, Affix } from 'antd';
import delegate from 'delegate';
import EditButton from './EditButton';
import { ping } from '../utils';
@ -14,12 +13,6 @@ export default class Article extends React.Component {
}
componentDidMount() {
// Add ga event click
this.delegation = delegate(this.node, '.resource-card', 'click', (e) => {
if (window.ga) {
window.ga('send', 'event', 'Download', 'resource', e.delegateTarget.href);
}
}, false);
this.componentDidUpdate();
}
@ -39,9 +32,16 @@ export default class Article extends React.Component {
componentWillUnmount() {
clearTimeout(this.pingTimer);
if (this.delegation) {
this.delegation.destroy();
}
onResourceClick = (e) => {
if (!window.gtag && e.target.className !== 'resource-card') {
return;
}
window.gtag('event', 'resource', {
event_category: 'Download',
event_label: e.target.href,
});
}
getArticle(article) {
@ -78,7 +78,8 @@ export default class Article extends React.Component {
const isNotTranslated = locale === 'en-US' && typeof title === 'object';
return (
<DocumentTitle title={`${title[locale] || title} - Ant Design`}>
<article className="markdown" ref={(node) => { this.node = node; }}>
{ /* eslint-disable-next-line */ }
<article className="markdown" onClick={this.onResourceClick}>
{isNotTranslated && (
<Alert
type="warning"