Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Add Google Analytics action for the styling menu #38085

Merged
merged 4 commits into from
Jul 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions docs/src/modules/components/DemoToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ export default function DemoToolbar(props) {
>
<MenuItem
value={CODE_STYLING.SYSTEM}
data-ga-event-category="demo"
data-ga-event-action="styling-system"
Copy link
Member

Choose a reason for hiding this comment

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

Should we update

const CODE_STYLING = {
  SYSTEM: 'MUI System',
  TAILWIND: 'Tailwind',
  CSS: 'CSS',
};

to match?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried to follow how the other actions look like - they are all kebab-case.

data-ga-event-label={demo.gaLabel}
selected={styleSolution === CODE_STYLING.SYSTEM}
onClick={() => handleStylingSolutionChange(CODE_STYLING.SYSTEM)}
>
Expand All @@ -683,6 +686,9 @@ export default function DemoToolbar(props) {
</MenuItem>
<MenuItem
value={CODE_STYLING.TAILWIND}
data-ga-event-category="demo"
data-ga-event-action="styling-tailwind"
data-ga-event-label={demo.gaLabel}
selected={styleSolution === CODE_STYLING.TAILWIND}
onClick={() => handleStylingSolutionChange(CODE_STYLING.TAILWIND)}
>
Expand All @@ -693,6 +699,9 @@ export default function DemoToolbar(props) {
</MenuItem>
<MenuItem
value={CODE_STYLING.CSS}
data-ga-event-category="demo"
data-ga-event-action="styling-css"
data-ga-event-label={demo.gaLabel}
selected={styleSolution === CODE_STYLING.CSS}
onClick={() => handleStylingSolutionChange(CODE_STYLING.CSS)}
>
Expand Down
8 changes: 8 additions & 0 deletions docs/src/modules/components/GoogleAnalytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import loadScript from 'docs/src/modules/utils/loadScript';
import { useTheme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import { useNoSsrCodeVariant } from 'docs/src/modules/utils/codeVariant';
import { useNoSsrCodeStyling } from 'docs/src/modules/utils/codeStylingSolution';
import { useUserLanguage } from 'docs/src/modules/utils/i18n';
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';
import { useRouter } from 'next/router';
Expand Down Expand Up @@ -147,6 +148,13 @@ function GoogleAnalytics() {
});
}, [colorScheme]);

const codeStylingVariant = useNoSsrCodeStyling();
React.useEffect(() => {
window.gtag('set', 'user_properties', {
codeStylingVariant,
});
}, [codeStylingVariant]);

return null;
}

Expand Down
1 change: 1 addition & 0 deletions docs/src/modules/components/RichMarkdownElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export default function RichMarkdownElement(props) {
rawCSSTS: demo.rawCSSTS,
jsCSS: demoComponents[demo.moduleCSS] ?? null,
tsxCSS: demoComponents[demo.moduleTSCSS] ?? null,
gaLabel: fileNameWithLocation.replace(/^\/docs\/data\//, ''),
}}
disableAd={disableAd}
demoOptions={renderedMarkdownOrDemo}
Expand Down