This lab will use CloudBees Feature Management’s impressionHandler to forward flag information to a more robust analytics platform (we will use Google Analytics for this lab, but the abstracted process remains the same for integration with other tools). We can pass information about feature flags values evaluated on each client back for analysis. We’ll set-up the beginning process for A/B testing process.
NOTE: If you going through these workshops on your own, feel free to create your own Google Analytics dashboard. Use your own UA property tag when necessary.
microblog-frontend repository. Within the root directory, on the development branch, navigate to the public folder. Then select the index.html file.index.html file, and remove the comments on Line 5 and Line 10 so that the gtag.js can be seen. If using your own dashboard replace your UA property ID where appropriate.index.html<!DOCTYPE html>
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-165275127-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-165275127-1');
</script>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title>microblog</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css">
</head>
<body>
<noscript>
<strong>We're sorry but microblog-frontend doesn't work properly without JavaScript enabled. Please enable it to
continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>
development branch.development branch, navigate to the flags.js file (src/utils/flags.js).impresionHandler constant seen below:export const impressionHandler = (reporting, experiment) => {
if (experiment) {
console.log('Flag is ' + reporting.name + ', and value is ' + reporting.value)
window.gtag('event', reporting.name, {
'event_category': reporting.name,
'event_label': reporting.value
})
}
}
options constant, include a call to the newly defined impressionHandler. After the configurationFetchedHandler call, insert a comma then and make the impressionHandler part of the options as seen below:const options = {
configurationFetchedHandler: configurationFetchedHandler,
impressionHandler: impressionHandler
}
flags.js:import Rox from 'rox-browser'
import store from '../store'
import { betaAccess } from './users'
export const Flags = {
sidebar: new Rox.Flag(false),
title: new Rox.Flag(false)
}
export const configurationFetchedHandler = fetcherResults => {
console.log('The configuration status is: ' + fetcherResults.fetcherStatus)
if (fetcherResults.hasChanges && fetcherResults.fetcherStatus === 'APPLIED_FROM_NETWORK') {
window.location.reload(false)
} else if (fetcherResults.fetcherStatus === 'ERROR_FETCH_FAILED') {
console.log('Error occured! Details are: ' + fetcherResults.errorDetails)
}
}
export const impressionHandler = (reporting, experiment) => {
if (experiment) {
console.log('Flag is ' + reporting.name + ', and value is ' + reporting.value)
window.gtag('event', reporting.name, {
'event_category': reporting.name,
'event_label': reporting.value
})
}
}
async function initCloudBees () {
const options = {
configurationFetchedHandler: configurationFetchedHandler,
impressionHandler: impressionHandler
}
Rox.setCustomBooleanProperty('isLoggedIn', store.getters.isLoggedIn)
Rox.setCustomBooleanProperty('hasBetaAccess', betaAccess())
Rox.register('default', Flags)
await Rox.setup(process.env.VUE_APP_CLOUDBEES_KEY, options)
}
initCloudBees().then(function () {
console.log('Done loading CloudBees Feature Management')
})
development branch.
You have successfully completed the introductory CloudBees Feature Management workshop!