Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
[CARE-4941] Update usages of @prezly/analytics-nextjs
Browse files Browse the repository at this point in the history
  • Loading branch information
e1himself committed May 10, 2024
1 parent 8b405e7 commit 9665fc9
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { STORY_FILE, useAnalytics } from '@prezly/analytics-nextjs';
import { DOWNLOAD, useAnalytics } from '@prezly/analytics-nextjs';
import type { AttachmentNode } from '@prezly/story-content-format';
import { translations } from '@prezly/theme-kit-intl';
import { UploadcareFile } from '@prezly/uploadcare';
Expand Down Expand Up @@ -26,7 +26,7 @@ function Attachment({ node }: Props) {
const fileType = fileExtension?.toUpperCase();

function handleClick() {
track(STORY_FILE.DOWNLOAD, { id: file.uuid });
track(DOWNLOAD.ATTACHMENT, { id: file.uuid });
}

return (
Expand Down
6 changes: 3 additions & 3 deletions components/ContentRenderer/components/Gallery.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { STORY_GALLERY_IMAGE, useAnalytics } from '@prezly/analytics-nextjs';
import { VIEW, DOWNLOAD, useAnalytics } from '@prezly/analytics-nextjs';

Check failure on line 1 in components/ContentRenderer/components/Gallery.tsx

View workflow job for this annotation

GitHub Actions / ESLint

components/ContentRenderer/components/Gallery.tsx#L1

Member 'DOWNLOAD' of the import declaration should be sorted alphabetically (sort-imports)
import { Elements } from '@prezly/content-renderer-react-js';
import type { GalleryNode } from '@prezly/story-content-format';

Expand All @@ -13,10 +13,10 @@ function Gallery({ node }: Props) {
<Elements.Gallery
node={node}
onImageDownload={(image) => {
track(STORY_GALLERY_IMAGE.DOWNLOAD, { id: image.uuid });
track(DOWNLOAD.GALLERY_IMAGE, { id: image.uuid });
}}
onPreviewOpen={(image) => {
track(STORY_GALLERY_IMAGE.VIEW, { id: image.uuid });
track(VIEW.GALLERY_IMAGE, { id: image.uuid });
}}
/>
);
Expand Down
6 changes: 3 additions & 3 deletions components/ContentRenderer/components/Image.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { STORY_IMAGE, useAnalytics } from '@prezly/analytics-nextjs';
import { DOWNLOAD, VIEW, useAnalytics } from '@prezly/analytics-nextjs';

Check failure on line 1 in components/ContentRenderer/components/Image.tsx

View workflow job for this annotation

GitHub Actions / ESLint

components/ContentRenderer/components/Image.tsx#L1

Member 'useAnalytics' of the import declaration should be sorted alphabetically (sort-imports)
import { Elements } from '@prezly/content-renderer-react-js';
import type { ImageNode } from '@prezly/story-content-format';
import type { PropsWithChildren } from 'react';
Expand All @@ -14,10 +14,10 @@ function Image({ node, children }: PropsWithChildren<Props>) {
<Elements.Image
node={node}
onDownload={(image) => {
track(STORY_IMAGE.DOWNLOAD, { id: image.uuid });
track(DOWNLOAD.IMAGE, { id: image.uuid });
}}
onPreviewOpen={(image) => {
track(STORY_IMAGE.VIEW, { id: image.uuid });
track(VIEW.IMAGE, { id: image.uuid });
}}
>
{children}
Expand Down
8 changes: 0 additions & 8 deletions components/RichText/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { STORY_LINK, useAnalytics } from '@prezly/analytics-nextjs';
import type { LinkNode } from '@prezly/story-content-format';
import classNames from 'classnames';
import type { PropsWithChildren } from 'react';
Expand All @@ -8,20 +7,13 @@ interface Props {
}

function Link({ node, children }: PropsWithChildren<Props>) {
const { track } = useAnalytics();

function handleClick() {
track(STORY_LINK.CLICK, { href: node.href });
}

return (
<a
href={node.href}
className={classNames(
'text-neutral-200 underline hover:text-blue-400 active:text-blue-500',
'focus:text-blue-400 focus:outline-none',
)}
onClick={handleClick}
>
{children}
</a>
Expand Down
7 changes: 4 additions & 3 deletions pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnalyticsContextProvider } from '@prezly/analytics-nextjs';
import { AnalyticsProvider, Tracking } from '@prezly/analytics-nextjs';
import { DEFAULT_LOCALE, LocaleObject } from '@prezly/theme-kit-core';
import type { PageProps } from '@prezly/theme-kit-nextjs';
import { NewsroomContextProvider } from '@prezly/theme-kit-nextjs';
Expand Down Expand Up @@ -36,14 +36,15 @@ function App({ Component, pageProps }: AppProps) {
defaultLocale={DEFAULT_LOCALE}
messages={translations}
>
<AnalyticsContextProvider
<AnalyticsProvider
isEnabled={isTrackingEnabled}
newsroom={newsroom}
story={currentStory}
>
<Tracking />
{/* eslint-disable-next-line react/jsx-props-no-spreading */}
<Component {...customPageProps} />
</AnalyticsContextProvider>
</AnalyticsProvider>
</IntlProvider>
</NewsroomContextProvider>
);
Expand Down

0 comments on commit 9665fc9

Please sign in to comment.