Feature Flags

Enable a Flagged Feature

developers must take certain actions to ensure a newly developed feature works with a feature flag before you can enable a flagged feature, you must set up feature flags on your site by adding the necessary code see getting started with feature flags for more information coding the feature flag trigger the code for the new feature must include a means of being triggered by the feature flag created for it for example, imagine that your development team has created a new custom checkout flow that you want to test on your site using a feature flag the code for that new checkout flow would need to include something like the following to trigger the feature flag example code to trigger a feature flag // the function that is run when the checkout button is pressed function oncheckoutbuttonclick( ){ // check on the flag created in the ui if(featureflags\['new checkout flow flag']\['enabled']){ triggernewcheckoutflow( ); } else{ triggeroldcheckoutflow( ); } } in this example, the new checkout flow is developed in the triggernewcheckoutflow() function, and the old checkout flow is contained in the triggeroldcheckoutflow() function new checkout flow flag is the name of the feature flag you made in monetate (see create a feature flag for more information ) turning on a flagged feature to get the configuration for a feature flag, navigate to the /features/1/flags endpoint using your account tuple (for example, https //sb monetate net/features/1/flags/a 123456/p/commerce com/ ) the json entry returned shows the name and percentage chosen for available features response to feature flag configuration request {"test red" {"percent" 50}} monetate provides helper functions that allow you to effectively parse this data function to parse feature flag configuration data window\ monetate featureflag {hash f, isfeatureenabled f, parsetogglesconfig f} hash f qi(a,b) isfeatureenabled f ri(a,b,c) parsetogglesconfig f (a,b) parsetogglesconfig(config, mid) adds an enabled field in the json entry with true or false based on the monetate id (mid) so that you can have the entire config ready for use feature flag parsetogglesconfig var config = {'foo' {'percent' 50}, 'baz' {'percent' 100}}; var mid = "2 162744605 1589391933748"; console log("config as received ", config); config as received foo { }, baz { }} 	 baz {percent 100} 	 foo {percent 50} 	 proto object monetate featureflag parsetogglesconfig(config, mid); console log("config as parsed ", config); config as parsed foo { }, baz { }} 	 baz {percent 100, enabled true} 	 foo {percent 50, enabled false} 	 proto object isfeatureenabled(featname, config, mid) is similar to parsetogglesconfig but returns true or false for an individual feature and leaves the config unchanged feature flag isfeatureenabled var config = {'foo' {'percent' 50}, 'baz' {'percent' 100}}; var mid = "2 162744605 1589391933748"; var fooenabled = monetate featureflag isfeatureenabled('foo', config, mid); var bazenabled = monetate featureflag isfeatureenabled('baz', config, mid); console log("the feature 'foo' is enabled? ", fooenabled); console log("the feature 'baz' is enabled? ", bazenabled); the feature 'foo' is enabled? false the feature 'baz' is enabled? true hash(mid, featname) ensures that every visitor gets a consistent percentile by taking the mid and a name of a feature and turning it into a percentage, it ensures uniqueness and consistency amongst visitors, even distributions, and a standard for re creation on other platforms if used on another platform, the hash function can be recreated for a consistent user experience because the percentile is the same the hash modulo 100 gives you the percentile and represents an enabled feature if less than the flag's percentage or disabled if equal to or greater than the flag's percentage feature flag hash var featname = "featurename"; var mid = "2 162744605 1589391933748"; var percentile = monetate featuretoggle hash(mid, featname) % 100; console log("the user " + mid + " is in the " + percentile + " percentile for " + featname); the user 2 162744605 1589391933748 is in the 67 percentile for featurename