The web content provides a comprehensive guide on integrating GrowthBook with WordPress for free and advanced A/B split testing, as an alternative to limited or paid WordPress plugins.
Abstract
The article discusses the integration of GrowthBook with WordPress websites for conducting A/B split testing. It highlights the limitations of existing WordPress plugins for split testing, with Nelio being a notable exception that requires payment beyond 500 views per month. GrowthBook is presented as a free and open-source solution with unlimited views for up to three users per organization. The guide covers the initial setup, including creating a GrowthBook account, connecting Google Analytics 4 (GA4) as a data source, and configuring Google Cloud BigQuery for data warehousing. It also details the process of connecting GrowthBook to WordPress using the JavaScript SDK and modifying the code to ensure GDPR compliance. The article emphasizes the flexibility and potential of GrowthBook for small websites to conduct experiments on a larger scale, such as testing different button colors on a website. It concludes with instructions on creating and starting experiments, monitoring results, and utilizing additional resources like documentation and YouTube tutorials for further guidance.
Opinions
The author suggests that existing WordPress plugins for split testing are insufficient, either due to cost or limitations on usage.
GrowthBook is favorably reviewed for its cost-effectiveness, GDPR compliance, and flexibility in experimentation.
The integration process is deemed suitable for intermediate to advanced users due to the need for some knowledge in CSS and JavaScript.
The article implies that the combination of GrowthBook and WordPress can provide powerful testing capabilities, especially for small websites that might not justify the cost of paid solutions.
The author provides a step-by-step guide with a positive outlook on the ease of setting up GrowthBook with WordPress, despite the complexity involved in handling cookies and GDPR compliance.
The use of Google Analytics 4 and Google Cloud BigQuery is recommended for data tracking and analysis within GrowthBook, indicating a preference for these tools in the setup process.
Setting up GrowthBook with WordPress to free A/B split testing
If you are looking in the WordPress plugins market, you won’t find anything decent for split-testing, except Nelio, which is great but paid after 500 views / month, and if you have a small website and only want to experiment with a few buttons but on a much larger scale, let’s say 2000 views, it’s not worth to pay 30 USD.
Here it comes GrowthBook, which is free with unlimited views for 3 users / organization, not to mention that it is open source, and you can self-host if you want to bypass some other limits, but it’s not the case here.
Example of experimenting with 3 variants
It is also compliant with GDPR and other privacy policies around the world.
Note: for the example below, you should already have set up the Google Analytics 4 for your WordPress website. If you don’t, you can use Site Kit.
This is for intermediate and advanced users, as it will require a bit of knowledge of CSS and JavaScript to fully implement your experiment, but it will give you unlimited flexibility.
First steps
Create an account on the GrowthBook, it’s easy, fast.
GrowthBook dashboard
Next, let’s connect the Google Analytics 4 domain as data source.
Add new data source, GA4, to GrowthBook
Now you have to connect the GA4 using Google Cloud BigQuery as data warehouse.
According to the BigQuery page, “All customers get 10 GB storage and up to 1 TB queries free per month.”, fair enough for many experiments on small user-base websites.
To get the requested JSON file from Google Cloud, follow this video between 0:20 and 3:52. At data location, select your region to comply to privacy policy, e.g., for E.U. GDPR select EU.
After you obtained the JSON to the service account, you can add it to the GrowthBook.
Connect Google Cloud account with the GrowthBook
After you save, you can click to “View schema browser” to see your data.
Verify if the data is readable
Please note that if your Google Analytics 4 integration with the BigQuery Link is fresh, then you have to wait at least one day to get data into the BigQuery, then you can see the metrics inside GrowthBook.
You can continue to WordPress connection even with no data yet.
Let the GrowthBook to discover metrics using the BigQuery GA4 data
Connecting to WordPress
This can be done using JavaScript SDK of the GrowthBook quite easy.
GrowthBook JavaScript SDK setup
Please note the “clientKey” and modify in the code below!
Add the loader script to your WordPress page <head> using a script inserter plugin, like WPCode. Check here for updated script link.
<!-- Creates `window.growthbook` with all of the exported classes --><scriptid="growthbook-sdk"src="https://cdn.jsdelivr.net/npm/@growthbook/growthbook/dist/bundles/index.min.js"></script>
This is using the GA4 cookie, so if you handle the privacy policy in your region, like GDPR, using a plugin, this script will comply by not running till user will accept the statistics tracking.
Be sure the code below is put after the Google Tag for GA4 script (gtag). You can check the console for “no gtag” message, should be none.
<!-- Note: modify the script with GrowthBook JavaScript SDK setup key --><script>
(function() {
// Using the GTAG clientID, so this way we don't set any new cookie - GDPR, cookie lawconst ga_cookie = document.cookie.match(/_ga=(.+?);/);
// Wait for the SDK to load before starting GrowthBookif (window.growthbook) {
startGrowthbook();
} else {
document.querySelector("#growthbook-sdk").addEventListener("load", startGrowthbook);
}
functionstartGrowthbook() {
if (!window.growthbook) return;
// Do not run if the GA4 cookie is not setif (!ga_cookie) return;
let clientId = ga_cookie[1].split('.').slice(-2).join(".");
let gb = new growthbook.GrowthBook({
apiHost: "https://cdn.growthbook.io",
clientKey: "sdk-YOUR-SDK-KEY",
enableDevMode: true,
// TODO: Add decryptionKey if using encryptionattributes: {
id: clientId
// Add any other attributes here
},
trackingCallback: function(experiment, result) {
// Track using GA4if ("gtag"inwindow) {
window.gtag("event", "experiment_viewed", {
event_category: "experiment",
experiment_id: experiment.key,
variation_id: result.variationId,
gb_user_id: clientId,
});
} else {
console.log("no gtag");
}
}
})
// TODO: Instrument DOM with AB test logic
gb.loadFeatures().then(function() {
// Run your experiment code here// START: Adjust or delete this, according to your experiment/*
* Note: this is just an example for a feature named "buttom-button-color".
* Will add CSS to the head according to the experiment feature value.
* Look below at feature configuration.
*/// Get the value of a string/JSON/number feature with a fallbackconst color = gb.getFeatureValue("bottom-button-color", "blue");
// Create a style elementconst styleElement = document.createElement('style');
styleElement.type = 'text/css';
// Define the CSS rules based on the feature valuelet cssRules = '';
// Change buttons css color according to the value// By default they are blue so no changes for thatswitch (color) {
case"red":
console.log("Set buttons to red theme.");
cssRules = '.buttonbottom { background: red; }';
break;
case"yellow":
console.log("Set buttons to yellow theme.");
cssRules = '.buttonbottom { background: black; color: yellow; }';
break;
}
// Add the CSS rules to the style element
styleElement.appendChild(document.createTextNode(cssRules));
// Append the style element to the head of the documentdocument.head.appendChild(styleElement);
// END: Adjust or delete this, according to your experiment
});
}
})();
</script>
After you save, and clean the WordPress cache if you are using any cache plugin, you can refresh the front-page and then check if the GrowthBook SDK is connected properly.
Verify if the GrowthBook SDK is connected properly
Experimenting
Now you have finish set up the connection of the GrowthBook it’s time to start A/B experimenting. You can read more about data you can pass to GrowthBook on the JavaScript SDK page and modify the script above.
Create a new experiment in the “Experiments” menu:
Example experiment with 3 variations
I want to change the colors of floating buttons at the bottom of the website for a total of 3 variants, let’s say blue, red, yellow.
Of course, you have a lot of options and targeting features here. You can read more in the documentation.
Let’s “Add Feature Flag”:
Set up an feature for the experiment
After you're adding the feature and start the experiment, or ideally before starting it, you can handle the feature change inside the code above, that already include an example for this specific feature.
Start the experiment 🚀!
Congratulations!
Now wait to get your awesome experiment results 🥳.
Don’t forget the next days to go back to the “Data Sources” and add metrics.