From 85aa74202abb9380e34037ff1041f25e277e2cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B8=85?= Date: Thu, 6 Jun 2019 18:47:31 +0800 Subject: [PATCH] add block a analytics to ga --- src/components/CopyBlock/index.tsx | 24 +++++++++++++++++++++++- src/typings.d.ts | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/components/CopyBlock/index.tsx b/src/components/CopyBlock/index.tsx index 0f7e6b92..bb24d584 100644 --- a/src/components/CopyBlock/index.tsx +++ b/src/components/CopyBlock/index.tsx @@ -4,6 +4,7 @@ import styles from './index.less'; import { connect } from 'dva'; import * as H from 'history'; import { FormattedMessage } from 'umi-plugin-react/locale'; +import { isAntDesignPro } from '@/utils/utils'; const firstUpperCase = (pathString: string) => { return pathString @@ -13,13 +14,34 @@ const firstUpperCase = (pathString: string) => { .filter(s => s) .join(''); }; + +// when click block copy, send block url to ga +const onBlockCopy = (label: string) => { + if (!isAntDesignPro()) { + return; + } + const ga = window && (window as any).ga; + if (ga) { + ga('send', 'event', { + eventCategory: 'block', + eventAction: 'copy', + eventLabel: label, + }); + } +}; + const BlockCodeView: React.SFC<{ url: string; }> = ({ url }) => { const blockUrl = `npx umi block add ${firstUpperCase(url)} --path=${url}`; return (
- + onBlockCopy(url), + }} + > {blockUrl}
diff --git a/src/typings.d.ts b/src/typings.d.ts index d32d9d23..9606b9d7 100644 --- a/src/typings.d.ts +++ b/src/typings.d.ts @@ -20,6 +20,7 @@ declare module 'react-fittext'; declare module '@antv/data-set'; declare module 'nzh/cn'; +declare let ga: Function; // preview.pro.ant.design only do not use in your production ; // preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。 declare let ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION: 'site' | undefined; -- GitLab