Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 45
Add tracking to landing page#309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| 'use client'; | ||
| import { usePathname } from 'next/navigation'; | ||
| import { useEffect } from 'react'; | ||
| export default function RB2BLoader() { | ||
| const pathname = usePathname(); | ||
| useEffect(() => { | ||
| const existing = document.getElementById('rb2b-script'); | ||
| if (existing) existing.remove(); | ||
| const script = document.createElement('script'); | ||
| script.id = 'rb2b-script'; | ||
| script.src = `https://ddwl4m2hdecbv.cloudfront.net/b/${process.env.NEXT_PUBLIC_RB2B_ID}/${process.env.NEXT_PUBLIC_RB2B_ID}.js.gz`; | ||
| script.async = true; | ||
| document.body.appendChild(script); | ||
| }, [pathname]); | ||
Comment on lines
+9
to
+18
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
Also, consider if re-adding the script on every path change is necessary. If the tracking library supports it, it's more performant to load the script once and call a page-view tracking function on navigation. | ||
| return null; | ||
| } | ||
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.
For security, when loading third-party scripts, it's crucial to use Subresource Integrity (SRI). This ensures that the file your users fetch has not been tampered with. You should add an
integrityhash andcrossOriginattribute to the script tag. You will need to generate the hash for the specific version of the script you are loading.