Browse Source
Merge pull request #4399 from ant-design/add-block-analytics
add block a analytics to ga
pull/4416/head
陈帅
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
24 additions and
1 deletions
-
src/components/CopyBlock/index.tsx
-
src/typings.d.ts
|
|
|
@ -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 ( |
|
|
|
<div className={styles['copy-block-view']}> |
|
|
|
<Typography.Paragraph copyable={{ text: blockUrl }}> |
|
|
|
<Typography.Paragraph |
|
|
|
copyable={{ |
|
|
|
text: blockUrl, |
|
|
|
onCopy: () => onBlockCopy(url), |
|
|
|
}} |
|
|
|
> |
|
|
|
<code className={styles['copy-block-code']}>{blockUrl}</code> |
|
|
|
</Typography.Paragraph> |
|
|
|
</div> |
|
|
|
|
|
|
|
@ -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; |
|
|
|
|