Skip to content

Instantly share code, notes, and snippets.

@rmanalan
Last active October 5, 2020 21:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmanalan/ed3f3fb60de837a6061d076c4be8c5d2 to your computer and use it in GitHub Desktop.
Save rmanalan/ed3f3fb60de837a6061d076c4be8c5d2 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/launchdarkly-js-client-sdk@2.18.1/dist/ldclient.min.js"></script>
</head>
<body>
<h1>Hello World!</h1>
<p>
My first feature flag is <b><span id="flag"></span></b>
</p>
</body>
<script>
// User is anonymous, but will be uniquely identified
// so that subsequent visits obtain the same flag variation
var user = { anonymous: true };
// Obtain a client-side ID from https://app.launchdarkly.com/settings/projects
var ldclient = window.LDClient.initialize("<client-side-ID>", user);
// Wait for client to initialize, before checking flag variations
ldclient.on("ready", function() {
document.getElementById("flag").innerHTML = ldclient.variation("my-first-flag", false);
});
// Listen for changes to the flag. Update in realtime when it changes.
ldclient.on("change:my-first-flag", function(newVal, prevVal) {
document.getElementById("flag").innerHTML = newVal;
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment