- Help Center
- Integrations
-
Getting Started
-
Configuration
- Targeting
- Split URL
- Product Testing
- Full Stack
- Experiment Management
- CSP Configuration
- Experiment Execution
- Reports
- Exit Popups
- GTM Integration
- Troubleshooting
- Performance Optimization
- Event-Triggered Changes
- Holdout Groups
- Split URL Pages
- URL Parameters
- DataLayer
- Menu Configurations
- Traffic Exclusion
- Experiment Scheduling
- Dynamic Element Changes
- Price Targeting
- Experience Scheduling
- Privacy
- Hash Changes
- Async Tracking
- Selective Installation
- CSS Selectors
- Vue.js Integration
- Page Content
- Multipage Split URL
- Organic Traffic
- Visual Editor
- Server-Side Testing
- Traffic Bucketing
- GDPR Warnings
- Statistical Confidence
- Browser Privacy
- Query Parameters
- Embedded Videos
- Tracking Code Execution
- Simultaneous Experiments
- Tags
- Deployments
- Disable Testing
- Locations
- Programmatic Bucketting
- Query Parameter Handling
- Convert Library
- Variation Previews
- Experiment Editing
- Opt-Out Script
- Data Reset
- Body Hiding
- Visit-Specific Variations
- Variation Styling
- Preview Issues
- Variation Editing
- Full-Site Testing
- Blinking Variations
- Cross-Domain Cookies
- Regex Support
- Conversion Tracking
- SPA Testing
- Project Setup
- Cross-Domain Tracking
- Geo-Targeting
- Analytics Tools
- Campaign Tags
- Previewing
- IDs
- Query String Targeting
- Bounce Rate Goals
- Bot Filtering
- Query String Variables
- Custom Audiences
- Redirects
- Baseline
- Tracking Code Location
- Secure Cookies
- AngularJS
- Cloudflare
- Code Installation
-
Track Goals
- Form Tracking
- Cookie Management
- iFrame Click Tracking
- Performance Optimization
- Revenue Tracking
- Interaction Goals
- Form Submissions
- Advanced Goals
- Lazy Loading
- Multi-Conversions
- URL Parameters
- Bounce Rate Goals
- DataLayer Integration
- Scroll Depth
- Social Interactions
- Page Views
- Marketo Forms
- Feature Analysis
- AJAX Forms
- Revenue Tracking via GTM
- Order Outliers
- Cumulative Revenue
- Goal Templates
- Adding Revenue Goals
- JS-Based Goals
- Goal Basics
- Google Analytics Goals
- Social Sharing
- Dynamic Goals
- Typeform Integration
-
Target Visitors
- Geolocation
- Interaction Goals
- Goal-Based Targeting
- Weather Targeting
- Cookie-Based Targeting
- Page Visits
- Audience Management
- Audience Segmentation
- Experiment Targeting
- Advanced Audience Creation
- Audience Templates
- Audience Creation
- Data Layer Integration
- Manual Activation
- JavaScript Conditions
- Device Targeting
- Language Targeting
- IP-Based Exclusion
- Visitor Management
- Page Tagging
- Cookies
-
Troubleshooting
- Google Warnings
- Visual Editor
- HTTPS Content
- Logs
- Support Options
- Bootstrap
- Cookie Blocking
- Change History
- Mobile Debugging
- AdWords
- Bot Exclusion
- Domain Issues
- Cloudflare Issues
- Monitoring
- Cloaking Penalties
- Goal Editor Issues
- Variations
- Snippet Performance
- Changes Not Saved
- Blocked Visual Editor
- Goal Testing
- Visual Editor Browsing
- Experiment Issues
- Installation Verification
- Data Leak Prevention
- Usage Limits
- Experiment Previews
- GA4 Revenue
- Chrome Debugger Logs
- SPA Errors
- Checkout JSON Error
-
Analyze Results
-
Integrations
- Google Analytics
- Cookie Consent Platforms
- Microsoft Clarity
- Plausible
- Marketo
- HubSpot
- Tealium
- Smartlook
- Klaviyo
- Salesforce CRM
- FullStory
- Snowplow Analytics
- Webflow
- GA4 Roles
- Amplitude
- Segment
- React
- BigCommerce
- WooCommerce
- Active Campaign
- Google Tag Manager
- Mixpanel
- Zapier
- Inspectlet
- Crazy Egg
- LanderApp
- Unbounce
- Instapage
- Drupal
- PrestaShop
- Magento
- Roistat
- Piano Analytics
- Heap Analytics
- Kissmetrics
- Mouseflow
- Adobe Analytics
- Clicky
-
Account Management
-
Developers
-
What's New
-
Common Questions
-
Shopify
React: Serving different modules based on Variation
This Article Will Help You:
Overview
Convert can work alongside React using different methods. One of them is to serve different modules depending on the variation that Convert randomly selects for the visitors.
The advantages and disadvantages of this method are:
- You have a lot of flexibility by encapsulating variations in React modules.
- You will need to compile your code every time you create a new test.
How to
To enable the above we will need to use the Convert on-page api that will provide us with the ID of the variation randomly selected for your visitor. This selection happens as soon as the Convert script starts running when loaded via the Convert tracking code.
First, we will provide an example of the React container that will return the Variation that has been selected randomly for your visitor:
// convert-abtest-container.js
var ConvertAbTestContainer = React.createClass({
propTypes: {
experimentId: React.PropTypes.string.isRequired,
defaultVariationId: React.PropTypes.string.isRequired,
variations: React.PropTypes.arrayOf(React.PropTypes.shape({
variationId: React.PropTypes.string.isRequired,
component: React.PropTypes.element.isRequired
}))
},
getVariation: function () {
// Make sure you perform appropriate guard checks before using this in production!
var activeExperiments = window.convert.currentData.experiments;
var isExperimentActive = _.contains(activeExperiments, this.props.experimentId);
var variation, variationId;
if (isExperimentActive) {
// Gets the Original/Control id to see if it is in the active experiments.
variationId = Object.keys(window.convert.data.experiments[experimenId].vars)[0];
} else {
variationId = this.props.defaultVariationId;
}
variation = _.findWhere(this.props.variations, { variationId: variationId });
return variation;
},
render: function () {
return this.getVariation();
}
});
Next, we have this code example of how the first React container is called and then the corresponding Variation module served:
...
render: function () {
var variations = [
{ variationId: '123456790', component: <FirstVariationComponent/> },
{ variationId: '123456791', component: <SecondVariationComponent/> }
];
return (
<AbTestContainer
experimentId='123456789'
defaultVariationId='123456790'
variations={variations}
/>
);
}
...
Please read the Single Page Apps article to learn more on how to implement this type of experiment.