Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Optimizely + Next.js in coupled mode

Vote:
0

Hi,

In our new project we would like to implement react component with SSR instead of razor templates. For that I thought we would try a coupled mode, so in DXP we will have two applications one with optimizely and the second one with next.js. There will be a middleware in optimizely which all frontend request will forwared to the next.js. All fine and it seems to be working. There is only one issue. Request which are proxied to the next.js have not assigned cookies with personalization i.e: EPiNumberOfVisits, EPiStateMarker.  

So my question is: Do you have any experience with such approach? Is there any service which I can use to handle request before it's proxied to the Next.js so all required cookies for personalization will be assigned? 

#337170
Mar 11, 2025 11:28
Vote:
0

Hi,

I do not know how design pattern you are using for your project. But here is good template for kind of Optimizely Headless project https://github.com/remkoj/optimizely-saas-starter

#337451
Mar 22, 2025 3:25
Vote:
0

Hi

If your approach is similar to https://github.com/episerver/Foundation-spa-react/blob/master/src/Headless.Cms/Infrastructure/NodeJsMiddleware/NodeJsForwarder.cs you should be able to forward cookies from your CMS .Net app middleware proxy (which is assigned to the website domain) to your NodeJS app. Anyway the question is what exactly you want to do with the cookie inside the Next app, for example audience based personalization can is executed by the .Net CMS app and can manipulate the JSON which is then used to render the components in Next app (have a look how Content Delivery API does it).
If you want to have access to the cookies from client site in your Next.js code (for example inside useEffect hook) your domain cookies will be accesible in code, but it needs to have HTTPOnly = false, otherwise it won't be visible in javascript.

#337460
Mar 23, 2025 17:52
Vote:
0

Yes, the approach from the link is excatly what we are trying to use.  I also hoped that I will be able to forward cookies to my nodejs app but it seemas that the cookie is not assigned yet, when it is handled by the proxy middleware. It's somehow handled later, probably in some other optimizely middleware/controller. 

#337461
Mar 24, 2025 7:29
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.