Skip to content

Commit

Permalink
[docs] fix: analytics events (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
sstraatemans authored Aug 22, 2023
1 parent 468be4a commit 9f43e24
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ export const BottomPageSection: FC<IProps> = ({

const onClickAction = (page: 'prev' | 'next', href?: string): void => {
if (!href) return;

analyticsEvent(
page === 'next'
? EVENT_NAMES['click:next_page']
: EVENT_NAMES['click:previous_page'],
{
label: `to: ${href}`,
url: window.location.href,
to: href,
from: window.location.pathname,
},
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isEmailValid } from '@/utils';
import { analyticsEvent, EVENT_NAMES } from '@/utils/analytics';
import { ChangeEvent, MouseEvent, useState } from 'react';

interface IReturn {
Expand All @@ -23,6 +24,8 @@ export const useSubscribe = (): IReturn => {
): Promise<void> => {
event.preventDefault();

analyticsEvent(EVENT_NAMES['click:subscribe']);

try {
if (!canSubmit) return;
const res = await fetch('/api/subscribe', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const ListItem: FC<IProps> = ({

analyticsEvent(EVENT_NAMES['click:asidemenu_deeplink'], {
label: item.title,
url: slug,
hash: slug,
});

scrollArea?.querySelector(slug)?.scrollIntoView({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ export const Footer: FC = () => {
<IconButton
title="Go to our Github"
icon={SystemIcon.Github}
onClick={() => alert('todo, make an href')}
as="a"
href="https://github.com/kadena-community"
/>
<IconButton
title="Go to our Twitter"
icon={SystemIcon.Twitter}
onClick={() => alert('todo, make an href')}
as="a"
href="https://twitter.com/kadena_io"
/>
<IconButton
onClick={() => alert('todo, make an href')}
as="a"
href="https://www.linkedin.com/company/kadena-llc"
title="Go to our Linkedin"
icon={SystemIcon.Linkedin}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export const Header: FC<IProps> = ({ menuItems, layout = 'full' }) => {

<HeaderSocialIconGroup>
<IconButton
as="button"
as="a"
href="https://twitter.com/kadena_io"
title="Go to our Twitter"
icon={SystemIcon.Twitter}
color="inverted"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const ThemeToggle: FC = () => {
const newTheme = theme === 'dark' ? 'light' : 'dark';
setTheme(newTheme);
analyticsEvent(EVENT_NAMES['click:change_theme'], {
label: `toggle theme to ${newTheme}`,
theme: newTheme,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ export const SideMenu: FC<IProps> = ({ closeMenu, menuItems }) => {
e.preventDefault();
const value = e.currentTarget.value;
if (e.key === 'Enter') {
analyticsEvent(EVENT_NAMES['send:mobile_search'], {
label: value,
url: window.location.href,
analyticsEvent(EVENT_NAMES['click:mobile_search'], {
query: value,
});
// eslint-disable-next-line @typescript-eslint/no-floating-promises
router.push(`/search?q=${value}`);
Expand Down
7 changes: 6 additions & 1 deletion packages/apps/docs/src/components/Search/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ export const Search: FC<IProps> = ({ query, hasScroll, limitResults }) => {
} = useSemanticSearch(limitResults);

useEffect(() => {
if (query !== undefined && query.trim() !== '') {
if (
query !== undefined &&
query.trim() !== '' &&
tabName !== undefined &&
tabName.trim() !== ''
) {
if (tabName === 'qa') {
// eslint-disable-next-line @typescript-eslint/no-floating-promises
handleSearchSubmit(query);
Expand Down
21 changes: 1 addition & 20 deletions packages/apps/docs/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ import { markDownComponents } from '@/components/Markdown';
import { MenuProvider, ThemeProvider } from '@/hooks';
import { IPageMeta, IPageProps } from '@/types/Layout';
import { getLayout } from '@/utils';
import onExternalButtonClick from '@/utils/onExternalButtonClick';
import { MDXProvider } from '@mdx-js/react';
import { AppProps } from 'next/app';
import Head from 'next/head';
import React, { FC, useEffect } from 'react';
import React, { FC } from 'react';

const GlobalStyles = globalCss({
...baseGlobalStyles,
Expand Down Expand Up @@ -52,24 +51,6 @@ export const MyApp = ({

const Layout = getLayout(props.frontmatter.layout);

const handleBeforeUnload = (event: BeforeUnloadEvent): void => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const { href } = (event as any).originalTarget.activeElement;
onExternalButtonClick(href);
};

useEffect(() => {
window.addEventListener('beforeunload', handleBeforeUnload, {
capture: true,
});

return () => {
window.removeEventListener('beforeunload', handleBeforeUnload, {
capture: true,
});
};
}, []);

return (
<>
<Head>
Expand Down
6 changes: 2 additions & 4 deletions packages/apps/docs/src/utils/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ export const EVENT_NAMES = {
'click:asidemenu_deeplink': 'click:asidemenu_deeplink',
'click:change_theme': 'click:change_theme',
'click:open_searchmodal': 'click:open_searchmodal',
'send:mobile_search': 'send:mobile_search',
'click:mobile_search': 'click:mobile_search',
'click:mobile_menu_open': 'click:mobile_menu_open',
'click:open_twitter': 'click:open_twitter',
'click:open_github': 'click:open_github',
'click:open_linkedin': 'click:open_linkedin',
'click:edit_page': 'click:edit_page',
'click:previous_page': 'click:previous_page',
'click:next_page': 'click:next_page',
'click:newsletter': 'click:newsletter',
'click:search': 'click:search',
'click:subscribe': 'click:subscribe',
} as const;

export const COOKIE_CONSENTNAME = 'cookie_consent';
Expand Down
19 changes: 0 additions & 19 deletions packages/apps/docs/src/utils/onExternalButtonClick.ts

This file was deleted.

1 comment on commit 9f43e24

@vercel
Copy link

@vercel vercel bot commented on 9f43e24 Aug 22, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

alpha-docs – ./packages/apps/docs

alpha-docs-git-main-kadena-js.vercel.app
docs-silk-two.vercel.app
alpha-docs.kadena.io
alpha-docs-kadena-js.vercel.app

Please sign in to comment.