Skip to content

Commit

Permalink
Add click tracking on YouTube banner
Browse files Browse the repository at this point in the history
  • Loading branch information
kamranahmedse committed Sep 14, 2021
1 parent 7c6aee8 commit 0f117cf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 6 additions & 3 deletions components/sticky-banner.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Flex, Link, Text } from '@chakra-ui/react';
import YouTubeLogo from '../components/icons/youtube.svg';
import siteConfig from '../content/site.json';
import { event } from '../lib/gtag';

export function StickyBanner() {
return (
<Flex as={Link}
href={siteConfig.url.youtube}
bg={'yellow.300'}
color='gray.900'
// bg={'teal.900'}
// color='gray.300'
alignItems='center'
position='fixed'
left={0}
Expand All @@ -18,8 +17,12 @@ export function StickyBanner() {
justifyContent='center'
py='8px'
_hover={{ textDecoration: 'none', bg: 'yellow.400' }}
// _hover={{ textDecoration: 'none', bg: 'teal.800', color: 'gray.100' }}
target='_blank'
onClick={() => event({
category: 'Subscription',
action: 'Clicked the YouTube banner',
label: 'Sticky YouTube banner on Top'
})}
>
<YouTubeLogo style={{ height: '20px', display: 'inline-block', marginRight: '7px' }} />
<Text as='span' fontWeight={500} fontSize='14px'>
Expand Down
2 changes: 1 addition & 1 deletion lib/gtag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function firePageView(url: string) {
}

// https://developers.google.com/analytics/devguides/collection/gtagjs/events
export function event(props: { action: string; category: string; label: string; value: string; }) {
export function event(props: { action: string; category: string; label?: string; value?: string; }) {
const { action, category, label, value } = props;
if (!window.gtag) {
console.warn('Missing GTAG – Analytics disabled');
Expand Down
6 changes: 6 additions & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { getAllGuides, GuideType } from '../lib/guide';
import { getAllVideos, VideoType } from '../lib/video';
import siteConfig from '../content/site.json';
import Helmet from '../components/helmet';
import { event } from '../lib/gtag';

type HomeProps = {
roadmaps: RoadmapType[];
Expand All @@ -39,6 +40,11 @@ export default function Home(props: HomeProps) {

<Text fontSize={['14px', '14px', '16px']}>We also have a <Link textDecoration={'underline'}
href={siteConfig.url.youtube}
onClick={() => event({
category: 'Subscription',
action: 'Clicked the YouTube link',
label: 'YouTube link on home'
})}
target='_blank'
fontWeight={600}>YouTube
channel</Link> which we hope you are going to love.</Text>
Expand Down

0 comments on commit 0f117cf

Please sign in to comment.