Last active
October 5, 2020 21:00
-
-
Save rmanalan/ed3f3fb60de837a6061d076c4be8c5d2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://unpkg.com/[email protected]/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