diff --git a/docs/src/modules/components/Ad.js b/docs/src/modules/components/Ad.js index 01c7c0f2b32a36..1ae7a9d1237403 100644 --- a/docs/src/modules/components/Ad.js +++ b/docs/src/modules/components/Ad.js @@ -86,7 +86,6 @@ const inHouseAds = [ function Ad(props) { const { classes } = props; - const { current: random } = React.useRef(Math.random()); const t = useSelector(state => state.options.t); const timerAdblock = React.useRef(); @@ -161,24 +160,65 @@ function Ad(props) { if (adblock) { minHeight = 'auto'; - if (Math.random() >= 0.8) { + if (Math.random() < 0.2) { children = getAdblock(classes, t); } else { - children = ; + children = ; } } if (!children) { if (carbonOut || codeFundOut) { - children = ; + children = ; minHeight = 'auto'; - } else if (random >= 0.65) { + } else if (Math.random() < 0.35) { children = ; } else { children = ; } } + React.useEffect(() => { + // Avoid a flood of events. + if (Math.random < 0.1) { + return null; + } + + const delay = setTimeout(() => { + let type; + + if (children.type === AdCodeFund) { + type = 'codefund'; + } else if (children.type === AdCarbon) { + type = 'carbon'; + } else if (children.type === AdInHouse) { + type = 'in-house'; + } else { + type = 'disable-adblock'; + } + + window.ga('send', { + hitType: 'event', + eventCategory: 'ad', + eventAction: 'display', + eventLabel: type, + }); + + if (type === 'in-house') { + window.ga('send', { + hitType: 'event', + eventCategory: 'in-house-ad', + eventAction: 'display', + eventLabel: children.props.ad.name, + }); + } + }, 2000); + + return () => { + clearTimeout(delay); + }; + }, [children.type, children.props.ad]); + return ( {children} diff --git a/docs/src/modules/components/AdInHouse.js b/docs/src/modules/components/AdInHouse.js index 1f467accca4da8..237d5706fc80e2 100644 --- a/docs/src/modules/components/AdInHouse.js +++ b/docs/src/modules/components/AdInHouse.js @@ -44,6 +44,7 @@ const useStyles = makeStyles(theme => ({ export default function AdInHouse(props) { const { ad } = props; const classes = useStyles(); + /* eslint-disable material-ui/no-hardcoded-labels, react/no-danger */ return ( diff --git a/docs/src/modules/components/Demo.js b/docs/src/modules/components/Demo.js index 7a39b301991b80..672a9b647964cb 100644 --- a/docs/src/modules/components/Demo.js +++ b/docs/src/modules/components/Demo.js @@ -253,7 +253,6 @@ function Demo(props) { const showSourceHint = demoHovered && !sourceHintSeen; const DemoComponent = demoData.Component; - const gaCategory = demoOptions.demo; const demoName = getDemoName(demoData.githubLocation); const demoSandboxedStyle = React.useMemo( () => ({ @@ -339,7 +338,7 @@ function Demo(props) { demo={demo} codeOpen={codeOpen} codeVariant={codeVariant} - gaEventCategory={gaCategory} + gaEventLabel={demoOptions.demo} onLanguageClick={handleCodeLanguageClick} />
@@ -353,7 +352,8 @@ function Demo(props) { > - - - - - {demoOptions.hideEditButton ? null : ( @@ -393,6 +378,23 @@ function Demo(props) { )} + + + + + @@ -425,7 +428,8 @@ function Demo(props) { {demoOptions.hideEditButton ? null : ( @@ -433,14 +437,16 @@ function Demo(props) { )} {t('copySourceLinkJS')} diff --git a/docs/src/modules/components/DemoLanguages.js b/docs/src/modules/components/DemoLanguages.js index 0e917988fadc3d..f5f9b38c18c6eb 100644 --- a/docs/src/modules/components/DemoLanguages.js +++ b/docs/src/modules/components/DemoLanguages.js @@ -18,7 +18,7 @@ const styles = { }; function DemoLanguages(props) { - const { classes, codeOpen, codeVariant, demo, gaEventCategory, onLanguageClick } = props; + const { classes, codeOpen, codeVariant, demo, gaEventLabel, onLanguageClick } = props; const hasTSVariant = demo.rawTS; const t = useSelector(state => state.options.t); @@ -41,8 +41,9 @@ function DemoLanguages(props) { className={classes.toggleButton} value={CODE_VARIANTS.JS} aria-label={t('showJSSource')} - data-ga-event-category={gaEventCategory} + data-ga-event-category="demo" data-ga-event-action="source-js" + data-ga-event-label={gaEventLabel} > @@ -51,8 +52,9 @@ function DemoLanguages(props) { value={CODE_VARIANTS.TS} disabled={!hasTSVariant} aria-label={t('showTSSource')} - data-ga-event-category={gaEventCategory} + data-ga-event-category="demo" data-ga-event-action="source-ts" + data-ga-event-label={gaEventLabel} > @@ -66,7 +68,7 @@ DemoLanguages.propTypes = { codeOpen: PropTypes.bool.isRequired, codeVariant: PropTypes.string.isRequired, demo: PropTypes.object.isRequired, - gaEventCategory: PropTypes.string.isRequired, + gaEventLabel: PropTypes.string.isRequired, onLanguageClick: PropTypes.func, }; diff --git a/docs/src/modules/components/GoogleAnalytics.js b/docs/src/modules/components/GoogleAnalytics.js index 1d58556ac2bac3..26fdd1a61aaf2c 100644 --- a/docs/src/modules/components/GoogleAnalytics.js +++ b/docs/src/modules/components/GoogleAnalytics.js @@ -10,10 +10,9 @@ import { pathnameToLanguage } from 'docs/src/modules/utils/helpers'; // Foo // function handleClick(event) { - const rootNode = document; let element = event.target; - while (element && element !== rootNode) { + while (element && element !== document) { const category = element.getAttribute('data-ga-event-category'); // We reach a tracking element, no need to look higher in the dom tree.