
Security News
Vite+ Joins the Push to Consolidate JavaScript Tooling
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
@remkoj/optimizely-one-nextjs
Advanced tools
React components (both client & server) to integrate the browser-side products from Optimizely (Web Experimentation, Data Platform & Content Analytics / Recommendations)
Start by adding the package to your project:
yarn add @remkoj/optimizely-one-nextjs
Then make the service endpoints available by creating a new API route within Next.JS. For the app router this is done by creating this file:
app/api/me/[[...path]]/route.ts
Put the following code in this file to use the API Route handler from the package:
import { createOptimizelyOneApi } from '@remkoj/optimizely-one-nextjs/server';
const handler = createOptimizelyOneApi()
export const GET = handler
export const POST = handler
export const runtime = 'edge' // 'nodejs' (default) | 'edge'
export const dynamic = 'force-dynamic'
export const dynamicParams = true
export const fetchCache = 'default-no-store'
Within the global layout (or your "third party providers component", whatever applies best), add the Optimizely One Scripts (Scripts.Header
& Scripts.Footer
), Context Provider (OptimizelyOneProvider
), Page Activator (PageActivator
), and - if you want to - the demo gadget (OptimizelyOneGadget
).
import { Scripts } from '@remkoj/optimizely-one-nextjs/server'
import { OptimizelyOneProvider, PageActivator } from '@remkoj/optimizely-one-nextjs/client'
import OptimizelyOneGadget from '@remkoj/optimizely-one-nextjs/optimizely-one-gadget'
export type RootLayoutProps = {
children: React.ReactNode
}
export default function RootLayout({ children }: RootLayoutProps)
{
return <html>
<head>
<Scripts.Header />
</head>
<body>
<OptimizelyOneProvider value={{ debug: true }}>
<PageActivator />
{ children }
<OptimizelyOneGadget />
</OptimizelyOneProvider>
<Scripts.Footer />
</body>
</html>
}
Whenever you want to track additional events, use the provided hook to get to the context and send events.
'use client'
import React, { type FunctionComponent } from 'react'
import { useOptimizelyOne } from '@remkoj/optimizely-one-nextjs/client'
export const YourComponent : FunctionComponent<{}> = props => {
const opti = useOptimizelyOne()
function handler()
{
opti?.track({ event: "name", action: "action" })
}
return <button onClick={() => handler()}>Output</button>
}
FAQs
Unknown package
The npm package @remkoj/optimizely-one-nextjs receives a total of 399 weekly downloads. As such, @remkoj/optimizely-one-nextjs popularity was classified as not popular.
We found that @remkoj/optimizely-one-nextjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Evan You announces Vite+, a commercial, Rust-powered toolchain built on the Vite ecosystem to unify JavaScript development and fund open source.
Security News
Ruby Central’s incident report on the RubyGems.org access dispute sparks backlash from former maintainers and renewed debate over project governance.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.