Analytics Integrations¶
This section covers advanced topics for getting the most out of BoastPress AB Testing, including integration with analytics platforms, custom conversion tracking, developer hooks and filters, and performance optimization.
Integration with Analytics Platforms¶
Google Analytics Integration¶
You can integrate BoastPress AB Testing with Google Analytics to track test variations and conversions:
Google Analytics 4 (GA4) Integration¶
- Set up custom dimensions:
- In GA4, go to Admin > Custom Definitions > Custom Dimensions
-
Create a new event-scoped dimension named "AB Test Variation"
-
Add tracking code:
// Add this to your theme's footer or in a custom plugin document.addEventListener('abTestingLoaded', function(e) { // Get test data from the event const testData = e.detail; // Send to GA4 if (typeof gtag === 'function') { gtag('event', 'ab_test_impression', { 'ab_test_name': testData.testName, 'ab_test_variation': testData.versionName }); } });
-
Track conversions:
// On your conversion page document.addEventListener('abTestingConversion', function(e) { const conversionData = e.detail; if (typeof gtag === 'function') { gtag('event', 'ab_test_conversion', { 'ab_test_name': conversionData.testName, 'ab_test_variation': conversionData.versionName }); } });
Universal Analytics Integration¶
For sites still using Universal Analytics:
- Set up custom dimensions:
- In UA, go to Admin > Property > Custom Definitions > Custom Dimensions
-
Create a new dimension named "AB Test Variation"
-
Add tracking code:
document.addEventListener('abTestingLoaded', function(e) { const testData = e.detail; if (typeof ga === 'function') { ga('set', 'dimension1', testData.versionName); // Use your dimension index ga('send', 'event', 'AB Testing', 'Impression', testData.testName); } });
Other Analytics Platforms¶
Matomo (Piwik) Integration¶
document.addEventListener('abTestingLoaded', function(e) {
const testData = e.detail;
if (typeof _paq === 'object') {
_paq.push(['setCustomDimension', 1, testData.versionName]); // Use your dimension index
_paq.push(['trackEvent', 'AB Testing', 'Impression', testData.testName]);
}
});
Facebook Pixel Integration¶
document.addEventListener('abTestingLoaded', function(e) {
const testData = e.detail;
if (typeof fbq === 'function') {
fbq('trackCustom', 'ABTestImpression', {
testName: testData.testName,
versionName: testData.versionName
});
}
});
In the next section, we'll cover upgrading to the Pro version and its additional features.