{"__v":0,"_id":"579ba5198a700d290067cbc7","api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Looking for LaunchDarkly's v1 docs?\",\n  \"body\": \"You are currently viewing the docs for LaunchDarkly v2.  If you are still using our v1 SDKs,  then please see the [v.1 documentation](http://docs.launchdarkly.com/v1.0/docs).\\n\\nIf you have any questions, feel free to email us <a href=\\\"mailto:support:::at:::launchdarkly.com?Subject=Version%202\\\">support@launchdarkly.com</a>\"\n}\n[/block]\nSetting up LaunchDarkly to control your first feature flag takes only a few minutes. First, add the SDK to your project:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<dependency>\\n  <groupId>com.launchdarkly</groupId>\\n  <artifactId>launchdarkly-client</artifactId>\\n  <version>2.0.1</version>\\n</dependency>\",\n      \"language\": \"java\",\n      \"name\": \"Java\"\n    },\n    {\n      \"code\": \"pip install ldclient-py\",\n      \"language\": \"text\",\n      \"name\": \"Python\"\n    },\n    {\n      \"code\": \"gem install ldclient-rb\",\n      \"language\": \"text\",\n      \"name\": \"Ruby\"\n    },\n    {\n      \"code\": \"go get gopkg.in/launchdarkly/go-client.v2\",\n      \"language\": \"text\",\n      \"name\": \"Go\"\n    },\n    {\n      \"code\": \"npm install ldclient-node --save\",\n      \"language\": \"text\",\n      \"name\": \"Node.js\"\n    },\n    {\n      \"code\": \"php composer.phar require launchdarkly/launchdarkly-php\",\n      \"language\": \"php\",\n      \"name\": \"PHP\"\n    },\n    {\n      \"code\": \"Install-Package LaunchDarkly.Client\",\n      \"language\": \"text\",\n      \"name\": \".NET\"\n    }\n  ]\n}\n[/block]\nNow import the LaunchDarkly client in your application code:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"import com.launchdarkly.client.*;\",\n      \"language\": \"java\",\n      \"name\": \"Java\"\n    },\n    {\n      \"code\": \"from ldclient import LDClient\",\n      \"language\": \"python\",\n      \"name\": \"Python\"\n    },\n    {\n      \"code\": \"require 'ldclient-rb'\",\n      \"language\": \"ruby\",\n      \"name\": \"Ruby\"\n    },\n    {\n      \"code\": \"import ld \\\"github.com/launchdarkly/go-client\\\"\",\n      \"language\": \"go\",\n      \"name\": \"Go\"\n    },\n    {\n      \"code\": \"var LaunchDarkly = require('ldclient-node');\",\n      \"language\": \"javascript\",\n      \"name\": \"Node.js\"\n    },\n    {\n      \"code\": \"require 'vendor/autoload.php';\",\n      \"language\": \"php\",\n      \"name\": \"PHP\"\n    },\n    {\n      \"code\": \"using LaunchDarkly.Client;\",\n      \"language\": \"csharp\",\n      \"name\": \".NET\"\n    }\n  ]\n}\n[/block]\nNext, create a new LaunchDarkly client:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"LDClient ldClient = new LDClient(YOUR_SDK_KEY);\",\n      \"language\": \"java\",\n      \"name\": \"Java\"\n    },\n    {\n      \"code\": \"ld_client = LDClient(YOUR_SDK_KEY)\",\n      \"language\": \"python\",\n      \"name\": null\n    },\n    {\n      \"code\": \"ld_client = LaunchDarkly::LDClient.new(YOUR_SDK_KEY)\",\n      \"language\": \"ruby\"\n    },\n    {\n      \"code\": \"ld_client := ld.MakeClient(YOUR_SDK_KEY, 5*time.Second)\",\n      \"language\": \"go\"\n    },\n    {\n      \"code\": \"ldclient = LaunchDarkly.init(YOUR_SDK_KEY)\",\n      \"language\": \"javascript\",\n      \"name\": \"Node.js\"\n    },\n    {\n      \"code\": \"$client = new LaunchDarkly\\\\LDClient(YOUR_SDK_KEY);\",\n      \"language\": \"php\"\n    },\n    {\n      \"code\": \"LdClient ldClient = new LdClient(\\\"YOUR_SDK_KEY\\\");\",\n      \"language\": \"csharp\",\n      \"name\": \".NET\"\n    }\n  ]\n}\n[/block]\nFinally, create a feature flag on your [dashboard](https://app.launchdarkly.com). When you create a flag, you specify a unique feature key-- you'll use this key in your application code to check which variation of a feature flag a user will receive by calling the `variation` method (or `boolVariation` in typed languages):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"LDUser user = new LDUser(\\\"user@test.com\\\");\\nboolean showFeature = ldClient.boolVariation(\\\"your.feature.key\\\", user, false);\\nif (showFeature) {\\n  // application code to show the feature \\n}\\nelse {\\n  // the code to run if the feature is off\\n}\",\n      \"language\": \"java\",\n      \"name\": \"Java\"\n    },\n    {\n      \"code\": \"show_feature = ld_client.variation(\\\"your.flag.key\\\", {\\\"key\\\": \\\"user@test.com\\\"}, False)\\nif show_feature:\\n    # application code to show the feature\\nelse:\\n    # the code to run if the feature is off\",\n      \"language\": \"python\",\n      \"name\": \"Python\"\n    },\n    {\n      \"code\": \"show_feature = ld_client.variation(\\\"your.flag.key\\\", {:key => \\\"user@test.com\\\"}, false)\\nif show_feature\\n    # application code to show the feature\\nelse\\n    # the code to run if the feature is off\",\n      \"language\": \"ruby\",\n      \"name\": \"Ruby\"\n    },\n    {\n      \"code\": \"key := \\\"user@test.com\\\"\\nshow_feature := ld_client.BoolVariation(\\\"your.flag.key\\\", ld.User{Key: &key,}, false)\\nif (show_feature) {\\n    # application code to show the feature\\n} else {\\n    # the code to run if the feature is off \\n}\",\n      \"language\": \"go\",\n      \"name\": \"Go\"\n    },\n    {\n      \"code\": \"ldclient.once('ready', function() {\\n    ldclient.variation(\\\"your.flag.key\\\", {\\\"key\\\": \\\"user@test.com\\\"}, false,\\n     function(err, showFeature) {\\n        if (showFeature) {\\n          // application code to show the feature\\n        } else {\\n          // the code to run if the feature is off\\n        }\\n     });\\n});\",\n      \"language\": \"javascript\",\n      \"name\": \"Node.js\"\n    },\n    {\n      \"code\": \"$user = new LaunchDarkly\\\\LDUser(\\\"user@test.com\\\");\\nif ($client->variation(\\\"your.flag.key\\\", $user)) {\\n    # application code to show the feature\\n} else {\\n    # the code to run if the feature is off\\n}\",\n      \"language\": \"php\",\n      \"name\": \"PHP\"\n    },\n    {\n      \"code\": \"User user = User.WithKey(username);\\nbool showFeature = ldClient.BoolVariation(\\\"your.feature.key\\\", user, false);\\nif (showFeature) {\\n  // application code to show the feature \\n}\\nelse {\\n  // the code to run if the feature is off\\n}\",\n      \"language\": \"csharp\",\n      \"name\": \".NET\"\n    }\n  ]\n}\n[/block]\nThe second argument to `variation` is the `user` object. The only mandatory property is the user key-- this is what LaunchDarkly uses to identify each user. The key does need to be unique to each user-- a database key, an e-mail address, or a hash of an email address usually works. \n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Identifying users\",\n  \"body\": \"You don't have to send users to LaunchDarkly in advance. Just set up your users in `variation` calls and you're all set. \\n\\nHowever, if you want to pre-populate your dashboard with users, you can bulk import them via our [REST API](http://apidocs.launchdarkly.com/docs/bulk-create-events).\"\n}\n[/block]\nOnce you're ready to test your integration, head over to the [dev console](doc:dev-console) to get a real-time view of your feature flag requests as they're received. \n\nThat's it! Now you can manage the feature on your dashboard-- read on to see how to [target users](doc:targeting-users) or do [controlled rollouts](doc:controlled-rollouts) and [A/B tests](doc:running-an-ab-test) without re-deploying your application!\n\nTo see the advanced configuration options available for your platform's SDK, see the Reference guides section.","category":"579ba5198a700d290067cbc2","createdAt":"2014-12-16T22:12:45.170Z","excerpt":"","githubsync":"","hidden":false,"isReference":false,"link_external":false,"link_url":"","order":0,"parentDoc":null,"project":"5490ae5b0c7786160022fb50","slug":"getting-started","sync_unique":"","title":"Setup","type":"basic","updates":["577de6b4c7b5c50e00a708df"],"user":"5490ae350c7786160022fb4d","version":"579ba5198a700d290067cbc1","childrenPages":[]}
[block:callout] { "type": "info", "title": "Looking for LaunchDarkly's v1 docs?", "body": "You are currently viewing the docs for LaunchDarkly v2. If you are still using our v1 SDKs, then please see the [v.1 documentation](http://docs.launchdarkly.com/v1.0/docs).\n\nIf you have any questions, feel free to email us <a href=\"mailto:support@launchdarkly.com?Subject=Version%202\">support@launchdarkly.com</a>" } [/block] Setting up LaunchDarkly to control your first feature flag takes only a few minutes. First, add the SDK to your project: [block:code] { "codes": [ { "code": "<dependency>\n <groupId>com.launchdarkly</groupId>\n <artifactId>launchdarkly-client</artifactId>\n <version>2.0.1</version>\n</dependency>", "language": "java", "name": "Java" }, { "code": "pip install ldclient-py", "language": "text", "name": "Python" }, { "code": "gem install ldclient-rb", "language": "text", "name": "Ruby" }, { "code": "go get gopkg.in/launchdarkly/go-client.v2", "language": "text", "name": "Go" }, { "code": "npm install ldclient-node --save", "language": "text", "name": "Node.js" }, { "code": "php composer.phar require launchdarkly/launchdarkly-php", "language": "php", "name": "PHP" }, { "code": "Install-Package LaunchDarkly.Client", "language": "text", "name": ".NET" } ] } [/block] Now import the LaunchDarkly client in your application code: [block:code] { "codes": [ { "code": "import com.launchdarkly.client.*;", "language": "java", "name": "Java" }, { "code": "from ldclient import LDClient", "language": "python", "name": "Python" }, { "code": "require 'ldclient-rb'", "language": "ruby", "name": "Ruby" }, { "code": "import ld \"github.com/launchdarkly/go-client\"", "language": "go", "name": "Go" }, { "code": "var LaunchDarkly = require('ldclient-node');", "language": "javascript", "name": "Node.js" }, { "code": "require 'vendor/autoload.php';", "language": "php", "name": "PHP" }, { "code": "using LaunchDarkly.Client;", "language": "csharp", "name": ".NET" } ] } [/block] Next, create a new LaunchDarkly client: [block:code] { "codes": [ { "code": "LDClient ldClient = new LDClient(YOUR_SDK_KEY);", "language": "java", "name": "Java" }, { "code": "ld_client = LDClient(YOUR_SDK_KEY)", "language": "python", "name": null }, { "code": "ld_client = LaunchDarkly::LDClient.new(YOUR_SDK_KEY)", "language": "ruby" }, { "code": "ld_client := ld.MakeClient(YOUR_SDK_KEY, 5*time.Second)", "language": "go" }, { "code": "ldclient = LaunchDarkly.init(YOUR_SDK_KEY)", "language": "javascript", "name": "Node.js" }, { "code": "$client = new LaunchDarkly\\LDClient(YOUR_SDK_KEY);", "language": "php" }, { "code": "LdClient ldClient = new LdClient(\"YOUR_SDK_KEY\");", "language": "csharp", "name": ".NET" } ] } [/block] Finally, create a feature flag on your [dashboard](https://app.launchdarkly.com). When you create a flag, you specify a unique feature key-- you'll use this key in your application code to check which variation of a feature flag a user will receive by calling the `variation` method (or `boolVariation` in typed languages): [block:code] { "codes": [ { "code": "LDUser user = new LDUser(\"user@test.com\");\nboolean showFeature = ldClient.boolVariation(\"your.feature.key\", user, false);\nif (showFeature) {\n // application code to show the feature \n}\nelse {\n // the code to run if the feature is off\n}", "language": "java", "name": "Java" }, { "code": "show_feature = ld_client.variation(\"your.flag.key\", {\"key\": \"user@test.com\"}, False)\nif show_feature:\n # application code to show the feature\nelse:\n # the code to run if the feature is off", "language": "python", "name": "Python" }, { "code": "show_feature = ld_client.variation(\"your.flag.key\", {:key => \"user@test.com\"}, false)\nif show_feature\n # application code to show the feature\nelse\n # the code to run if the feature is off", "language": "ruby", "name": "Ruby" }, { "code": "key := \"user@test.com\"\nshow_feature := ld_client.BoolVariation(\"your.flag.key\", ld.User{Key: &key,}, false)\nif (show_feature) {\n # application code to show the feature\n} else {\n # the code to run if the feature is off \n}", "language": "go", "name": "Go" }, { "code": "ldclient.once('ready', function() {\n ldclient.variation(\"your.flag.key\", {\"key\": \"user@test.com\"}, false,\n function(err, showFeature) {\n if (showFeature) {\n // application code to show the feature\n } else {\n // the code to run if the feature is off\n }\n });\n});", "language": "javascript", "name": "Node.js" }, { "code": "$user = new LaunchDarkly\\LDUser(\"user@test.com\");\nif ($client->variation(\"your.flag.key\", $user)) {\n # application code to show the feature\n} else {\n # the code to run if the feature is off\n}", "language": "php", "name": "PHP" }, { "code": "User user = User.WithKey(username);\nbool showFeature = ldClient.BoolVariation(\"your.feature.key\", user, false);\nif (showFeature) {\n // application code to show the feature \n}\nelse {\n // the code to run if the feature is off\n}", "language": "csharp", "name": ".NET" } ] } [/block] The second argument to `variation` is the `user` object. The only mandatory property is the user key-- this is what LaunchDarkly uses to identify each user. The key does need to be unique to each user-- a database key, an e-mail address, or a hash of an email address usually works. [block:callout] { "type": "info", "title": "Identifying users", "body": "You don't have to send users to LaunchDarkly in advance. Just set up your users in `variation` calls and you're all set. \n\nHowever, if you want to pre-populate your dashboard with users, you can bulk import them via our [REST API](http://apidocs.launchdarkly.com/docs/bulk-create-events)." } [/block] Once you're ready to test your integration, head over to the [dev console](doc:dev-console) to get a real-time view of your feature flag requests as they're received. That's it! Now you can manage the feature on your dashboard-- read on to see how to [target users](doc:targeting-users) or do [controlled rollouts](doc:controlled-rollouts) and [A/B tests](doc:running-an-ab-test) without re-deploying your application! To see the advanced configuration options available for your platform's SDK, see the Reference guides section.