Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
How to make Component Variant in Google Optimize A/B testing in Next js

I was trying to make a component variant in google optimize instead of just text or color variant, But I could not find any better approach to do this. I want to know how I could connect(configure) the optimize with my code and can create a component variant. For eg: Suppose I have 2 components A and B, and if I want 50% of my traffic to view component A and rest to view component B. How Can I put this conditional rendering of component in google Optimize A/B testing? Stuck in it since a long time, kindly help.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You could both render all of your components on Reactjs, but style them with display: none

Then in google optimize A/B configs, you can choose which component to show or not by remove by adding display: block or back to display: none again.

But this way, there might be a flicker in your page when google optimize taking its effect, so please be cautious about that.

about 4 years ago · Juan Pablo Isaza Report

0

As Ryan Le says you can add component B in your code with display:none, then your code could be similar to:

<componentA>my component A</componentA>
<componentB style="display:none">my component B</componentB>

In your original version users will see only componentA, then in Optimize you create a variant and, for example, you can select componentA and add javascript change begin close label with code similar to:

document.querySlector("componentA").style.display = "none"; //or element.style.display = "none";
document.querySelector("componentB").style.display = "block";

Another way is to hide componentA with visual editor and write in Global JS the line to show componentB.

document.querySelector("componentB").style.display = "block";

And the most complicated way would be to use server-side experiment, you can get more info here: https://developers.google.com/optimize/devguides/experiments

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!