-
-
Notifications
You must be signed in to change notification settings - Fork 772
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
181 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { memo, useState } from 'react' | ||
import { useInView } from 'react-intersection-observer' | ||
|
||
import { useIsLogged } from '~/atoms' | ||
import { TrackerAction } from '~/constants/tracker' | ||
|
||
type ImpressionProps = { | ||
trackerMessage?: string | ||
action?: TrackerAction | ||
onTrack?: () => any | ||
} | ||
export const ImpressionView: Component< | ||
{ shouldTrack?: boolean } & ImpressionProps | ||
> = (props) => { | ||
const { shouldTrack = true, ...rest } = props | ||
if (!shouldTrack) { | ||
return <>{props.children}</> | ||
} | ||
return <ImpressionViewImpl {...rest} /> | ||
} | ||
|
||
const ImpressionViewImpl: Component<ImpressionProps> = memo((props) => { | ||
const [impression, setImpression] = useState(false) | ||
const isLogged = useIsLogged() | ||
const { ref } = useInView({ | ||
initialInView: false, | ||
triggerOnce: true, | ||
onChange(inView) { | ||
if (inView) { | ||
setImpression(true) | ||
|
||
if (isLogged) { | ||
return | ||
} | ||
document.dispatchEvent( | ||
new CustomEvent('impression', { | ||
detail: { | ||
action: props.action ?? TrackerAction.Impression, | ||
label: props.trackerMessage, | ||
}, | ||
}), | ||
) | ||
|
||
props.onTrack?.() | ||
} | ||
}, | ||
}) | ||
|
||
return ( | ||
<> | ||
{props.children} | ||
{!impression && <span ref={ref} />} | ||
</> | ||
) | ||
}) | ||
|
||
ImpressionViewImpl.displayName = 'ImpressionView' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use client' | ||
|
||
import Script from 'next/script' | ||
|
||
import { useAppConfigSelector } from './aggregation-data-provider' | ||
|
||
export const ScriptInjectProvider = () => { | ||
const scripts = useAppConfigSelector((config) => config.custom.scripts) | ||
if (!scripts) return null | ||
return ( | ||
<> | ||
{scripts.map((props) => ( | ||
<Script key={props.src} {...props} /> | ||
))} | ||
</> | ||
) | ||
} |
Oops, something went wrong.
1cfd22c
There was a problem hiding this comment.
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:
shiro – ./
innei.in
shiro-innei.vercel.app
springtide.vercel.app
shiro-git-main-innei.vercel.app