Skip to content

Commit

Permalink
feat: block increment views except on main domain
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorusclarence committed Dec 29, 2021
1 parent 713105e commit 76982eb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/constants/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,45 @@ import { getFromLocalStorage } from '@/lib/helper';

export const isProd = process.env.NODE_ENV === 'production';

/**
* Show command service on contents
* @see Comment.tsx
*/
export const commentFlag = isProd;

/**
* Get content meta from the database
* @see useContentMeta.tsx
*/
export const contentMetaFlag = isProd;

/**
* Increment content views
* @see useContentMeta.tsx
*/
export const incrementMetaFlag =
isProd && getFromLocalStorage('incrementMetaFlag') !== 'false';

/**
* Show Spotify Now Playing on footer
* @see Footer.tsx
*/
export const spotifyFlag = isProd;

/**
* Open API access to newsletter provider (subscribe and view count)
* @see SubscribeCard.tsx
*/
export const newsletterFlag = isProd;

/**
* Console to the browser greeting message
* @see Layout.tsx
*/
export const sayHelloFlag = isProd;

/**
* Only increase count when in specified domain meta
* @see _app.tsx
*/
export const blockDomainMeta = isProd;
7 changes: 7 additions & 0 deletions src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,20 @@ import '@/styles/mdx.css';
import '@/styles/dracula.css';
import '@/styles/nprogress.css';

import { blockDomainMeta } from '@/constants/env';

Router.events.on('routeChangeStart', nProgress.start);
Router.events.on('routeChangeError', nProgress.done);
Router.events.on('routeChangeComplete', nProgress.done);

function MyApp({ Component, pageProps }: AppProps) {
React.useEffect(() => {
hotjar.initialize(2702988, 6);

// Don't increment views if not on main domain
if (window.location.host !== 'theodorusclarence.com' && blockDomainMeta) {
localStorage.setItem('incrementMetaFlag', 'false');
}
}, []);

return (
Expand Down

1 comment on commit 76982eb

@vercel
Copy link

@vercel vercel bot commented on 76982eb Dec 29, 2021

Choose a reason for hiding this comment

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

Please sign in to comment.