{"category":{"version":"588861fa165af631008ee1b8","project":"54861bb654b3ce0b00367292","_id":"588861fa165af631008ee1c1","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-12-08T22:54:31.828Z","from_sync":false,"order":8,"slug":"2-personalization","title":"Cases & Dynamic Objects"},"parentDoc":null,"project":"54861bb654b3ce0b00367292","user":"54861b9f3681d914006992a4","version":{"__v":1,"_id":"588861fa165af631008ee1b8","project":"54861bb654b3ce0b00367292","createdAt":"2017-01-25T08:29:46.061Z","releaseDate":"2017-01-25T08:29:46.061Z","categories":["588861fa165af631008ee1b9","588861fa165af631008ee1ba","588861fa165af631008ee1bb","588861fa165af631008ee1bc","588861fa165af631008ee1bd","588861fa165af631008ee1be","588861fa165af631008ee1bf","588861fa165af631008ee1c0","588861fa165af631008ee1c1","588861fa165af631008ee1c2","588861fa165af631008ee1c3","588861fa165af631008ee1c4","588861fa165af631008ee1c5","588861fa165af631008ee1c6","588861fa165af631008ee1c7","588861fa165af631008ee1c8","588861fa165af631008ee1c9"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"5.0.0","version":"5.0"},"_id":"588861fa165af631008ee1fe","__v":0,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-12-09T10:07:54.733Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"never","params":[],"url":""},"isReference":false,"order":58,"body":"Elasticode enables you to create personalization by targeting specific users.\nEach user will experience your app differently, based on the cases you've defined, and the dynamic objects that can be changed in the dashboard.\n\nFirst, integrate the following within your code.\n\n\n\n\n**In order to apply these configurations, change the following code in your app delegate** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions\\n  (NSDictionary *)launchOptions {\\n  [ElastiCode setAPIKey::::at:::\\\"<APIKey>\\\"]; \\n        \\n\\n  ECSessionParams* params = [ECSessionParams createInProduction:NO];\\n\\t// Your cases defines  \\n  [ElastiCode setSessionParams:params];\\n\\n\\t[ElastiCode ready];\\n  return YES;\\n}\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"class AppDelegate: UIResponder, UIApplicationDelegate {\\nvar window: UIWindow?\\n\\nfunc application(application: UIApplication, didFinishLaunchingWithOptions\\n       launchOptions: [NSObject: AnyObject]?) -> Bool {\\n   // Override point for customization after application launch.\\n   \\n    ElastiCode.setAPIKey(\\\"<APIKey>\\\")\\n    let params:ECSessionParams = ECSessionParams .createInProduction(false)\\n    // Your cases defines\\n    ElastiCode.setSessionParams(params)\\n    ElastiCode.ready()\\n    \\n    return true\\n}\",\n      \"language\": \"swift\"\n    },\n    {\n      \"code\": \"@Override\\nprotected void onCreate(Bundle savedInstanceState) {\\n  super.onCreate(savedInstanceState);\\n  setContentView(R.layout.ac_main);\\n\\n  elasticode = Elasticode.getInstance(this, \\\"<APIKey>\\\", elasticodeObserver);\\n  ElasticodeSessionParams params = \\n    new ElasticodeSessionParams(MainActivity.this);\\n  \\n\\t// Your cases defines\\n  \\n  elasticode.setSessionParams(params);\\n  \\n  elasticode.ready();\\n\\n}\",\n      \"language\": \"java\"\n    },\n    {\n      \"code\": \"onDeviceReady: function() {\\n  app.receivedEvent('deviceready');\\n  window.elasticode.setAndroidApiKey(\\\"<androidApiKey>\\\");\\n  window.elasticode.setIOSApiKey(\\\"<iOSApiKey>\\\");\\n\\n  var params = window.elasticode.createSessionParamsObject();\\n  params.data.defineDynamicObject(\\\"doTest-int\\\", params.ECType.int, 7);\\n  params.data.defineAppTrigger(\\\"Bla\\\", function(active){\\n    console.log(\\\"Trigger Bla - \\\"+active);\\n  });\\n  elasticode.setActions()\\n    window.elasticode.setSessionParams(false, params);\\n  window.elasticode.ready();\\n},\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n##**Defining A Case - Setting relevant hypotheses in advanced**  \nThe developer should define a case by:  \na) Name  \nb) Number of states it includes.\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Key\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description/Example\",\n    \"0-0\": \"Case name\",\n    \"0-1\": \"String\",\n    \"0-2\": \"Indicate the name of the defined case. For example: \\\"Login button\\\"\",\n    \"1-2\": \"A number indicating the probable number of options for this specific case\",\n    \"1-0\": \"numberOfStates\",\n    \"1-1\": \"Integer\"\n  },\n  \"cols\": 3,\n  \"rows\": 2\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[params.data defineCase: @\\\"First Button\\\" withNumOfStates: 3];\",\n      \"language\": \"objectivec\",\n      \"name\": null\n    },\n    {\n      \"code\": \"params.data .defineCase(\\\"First Button\\\", withNumOfStates: 3)\",\n      \"language\": \"objectivec\",\n      \"name\": \"Swift\"\n    },\n    {\n      \"code\": \"params.data.defineCase(\\\"First Button\\\", 3);\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Please note that cases can be used ONLY after sync\",\n  \"body\": \"Remember, you can only use the personalization capabilities of cases after the sync was finished.\"\n}\n[/block]\n#**Using Cases**\nAfter you've reached a decision point, we fire the `stateIndexForCase` method that retrieves the relevant answer for it. i.e.: what to display? what option to choose? should we display or not? etc. \n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Key\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description/Example\",\n    \"0-0\": \"CaseName\",\n    \"0-1\": \"String\",\n    \"0-2\": \"Indicate the name of the case you are defining, for example: \\\"Login button\\\"\"\n  },\n  \"cols\": 3,\n  \"rows\": 1\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"switch ([ElastiCode stateIndexForCase:@\\\"First Button\\\"]){\\n  case 1:\\n\\t  b1.backgroundColor = [UIColor cyanColor];\\n  \\tbreak;\\n  case 2:\\n\\t  b1.backgroundColor = [UIColor magentaColor];\\n  \\tbreak;\\n  case 0:\\n  default:\\n  \\tb1.backgroundColor = [UIColor yellowColor];\\n\\t  break;\\n}\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"switch (ElastiCode .stateIndexForCase(\\\"First Button\\\")){\\n  case 1:\\n\\t  b1.backgroundColor = UIColor.cyanColor()\\n    break;\\n  case 2:\\n  \\tb1.backgroundColor = UIColor.magentaColor()\\n    break;\\n  case 0:\\n  default:\\n\\t  b1.backgroundColor = UIColor.yellowColor()\\n    break;\\n}\",\n      \"language\": \"objectivec\",\n      \"name\": \"Swift\"\n    },\n    {\n      \"code\": \"int stateIndex = elasticode.stateIndexForCase(\\\"First Button\\\");\\nswitch (stateIndex){\\n\\tcase 1:\\n  \\tbreak;\\n\\tcase 2:\\n  \\tbreak;\\n  case 0:\\n  default:\\n\\t\\tbreak;\\n}\",\n      \"language\": \"java\",\n      \"name\": \"Java\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Optional\",\n  \"body\": \"In case you are loading the data before using it, follow these two steps:\"\n}\n[/block]\nA) Get the selected state index of a case.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"int index = [ElastiCode stateIndexWithoutVisitForCase:@\\\"Buy Button\\\"];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"let index = ElastiCode .stateIndexWithoutVisitForCase(\\\"Buy Button\\\")\",\n      \"language\": \"objectivec\",\n      \"name\": \"Swift\"\n    },\n    {\n      \"code\": \"int stateIndex = elasticode.stateIndexWithoutVisitForCase(\\\"Buy Button\\\");\",\n      \"language\": \"java\",\n      \"name\": \"Java\"\n    }\n  ]\n}\n[/block]\nB) Once a case is visible to an end user, alert our server about it:\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Key\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description/Example\",\n    \"0-0\": \"caseName\",\n    \"0-1\": \"String\",\n    \"0-2\": \"Name of the relevant case you would like to alert about\"\n  },\n  \"cols\": 3,\n  \"rows\": 1\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[ElastiCode visitCase:@\\\"Buy Button\\\"];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"ElastiCode .visitCase(\\\"Buy Button\\\")\",\n      \"language\": \"objectivec\",\n      \"name\": \"Swift\"\n    },\n    {\n      \"code\": \"elasticode.visitCase(\\\"Buy Button\\\");\",\n      \"language\": \"java\",\n      \"name\": \"Java\"\n    }\n  ]\n}\n[/block]\n##**Reaching a goal**\nIn order to optimise your app, we need to know what the desired action of each case is, and understand the conversion rate for each alternative.\n\nThe desired action should be defined within the code, by the developer and may be a click (e.g. on the “buy\" button),\na swipe or even the fact that a user had not left the screen for 2 minutes (if you aim for retention).\n\nTo notify Elasticode regarding a successful action:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[ElastiCode goalReached:@\\\"Buy Button\\\"];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"ElastiCode .goalReached(\\\"Buy Button\\\")\",\n      \"language\": \"objectivec\",\n      \"name\": \"Swift\"\n    },\n    {\n      \"code\": \"elasticode.goalReached(\\\"Buy Button\\\");\",\n      \"language\": \"java\",\n      \"name\": \"Java\"\n    }\n  ]\n}\n[/block]","excerpt":"Building cases and their relevant states, visits and actions","slug":"cases","type":"basic","title":"Creating Cases"}

Creating Cases

Building cases and their relevant states, visits and actions

Elasticode enables you to create personalization by targeting specific users. Each user will experience your app differently, based on the cases you've defined, and the dynamic objects that can be changed in the dashboard. First, integrate the following within your code. **In order to apply these configurations, change the following code in your app delegate** [block:code] { "codes": [ { "code": "- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions\n (NSDictionary *)launchOptions {\n [ElastiCode setAPIKey:@\"<APIKey>\"]; \n \n\n ECSessionParams* params = [ECSessionParams createInProduction:NO];\n\t// Your cases defines \n [ElastiCode setSessionParams:params];\n\n\t[ElastiCode ready];\n return YES;\n}", "language": "objectivec" }, { "code": "class AppDelegate: UIResponder, UIApplicationDelegate {\nvar window: UIWindow?\n\nfunc application(application: UIApplication, didFinishLaunchingWithOptions\n launchOptions: [NSObject: AnyObject]?) -> Bool {\n // Override point for customization after application launch.\n \n ElastiCode.setAPIKey(\"<APIKey>\")\n let params:ECSessionParams = ECSessionParams .createInProduction(false)\n // Your cases defines\n ElastiCode.setSessionParams(params)\n ElastiCode.ready()\n \n return true\n}", "language": "swift" }, { "code": "@Override\nprotected void onCreate(Bundle savedInstanceState) {\n super.onCreate(savedInstanceState);\n setContentView(R.layout.ac_main);\n\n elasticode = Elasticode.getInstance(this, \"<APIKey>\", elasticodeObserver);\n ElasticodeSessionParams params = \n new ElasticodeSessionParams(MainActivity.this);\n \n\t// Your cases defines\n \n elasticode.setSessionParams(params);\n \n elasticode.ready();\n\n}", "language": "java" }, { "code": "onDeviceReady: function() {\n app.receivedEvent('deviceready');\n window.elasticode.setAndroidApiKey(\"<androidApiKey>\");\n window.elasticode.setIOSApiKey(\"<iOSApiKey>\");\n\n var params = window.elasticode.createSessionParamsObject();\n params.data.defineDynamicObject(\"doTest-int\", params.ECType.int, 7);\n params.data.defineAppTrigger(\"Bla\", function(active){\n console.log(\"Trigger Bla - \"+active);\n });\n elasticode.setActions()\n window.elasticode.setSessionParams(false, params);\n window.elasticode.ready();\n},", "language": "javascript" } ] } [/block] ##**Defining A Case - Setting relevant hypotheses in advanced** The developer should define a case by: a) Name b) Number of states it includes. [block:parameters] { "data": { "h-0": "Key", "h-1": "Type", "h-2": "Description/Example", "0-0": "Case name", "0-1": "String", "0-2": "Indicate the name of the defined case. For example: \"Login button\"", "1-2": "A number indicating the probable number of options for this specific case", "1-0": "numberOfStates", "1-1": "Integer" }, "cols": 3, "rows": 2 } [/block] [block:code] { "codes": [ { "code": "[params.data defineCase: @\"First Button\" withNumOfStates: 3];", "language": "objectivec", "name": null }, { "code": "params.data .defineCase(\"First Button\", withNumOfStates: 3)", "language": "objectivec", "name": "Swift" }, { "code": "params.data.defineCase(\"First Button\", 3);", "language": "java" } ] } [/block] [block:callout] { "type": "info", "title": "Please note that cases can be used ONLY after sync", "body": "Remember, you can only use the personalization capabilities of cases after the sync was finished." } [/block] #**Using Cases** After you've reached a decision point, we fire the `stateIndexForCase` method that retrieves the relevant answer for it. i.e.: what to display? what option to choose? should we display or not? etc. [block:parameters] { "data": { "h-0": "Key", "h-1": "Type", "h-2": "Description/Example", "0-0": "CaseName", "0-1": "String", "0-2": "Indicate the name of the case you are defining, for example: \"Login button\"" }, "cols": 3, "rows": 1 } [/block] [block:code] { "codes": [ { "code": "switch ([ElastiCode stateIndexForCase:@\"First Button\"]){\n case 1:\n\t b1.backgroundColor = [UIColor cyanColor];\n \tbreak;\n case 2:\n\t b1.backgroundColor = [UIColor magentaColor];\n \tbreak;\n case 0:\n default:\n \tb1.backgroundColor = [UIColor yellowColor];\n\t break;\n}", "language": "objectivec" }, { "code": "switch (ElastiCode .stateIndexForCase(\"First Button\")){\n case 1:\n\t b1.backgroundColor = UIColor.cyanColor()\n break;\n case 2:\n \tb1.backgroundColor = UIColor.magentaColor()\n break;\n case 0:\n default:\n\t b1.backgroundColor = UIColor.yellowColor()\n break;\n}", "language": "objectivec", "name": "Swift" }, { "code": "int stateIndex = elasticode.stateIndexForCase(\"First Button\");\nswitch (stateIndex){\n\tcase 1:\n \tbreak;\n\tcase 2:\n \tbreak;\n case 0:\n default:\n\t\tbreak;\n}", "language": "java", "name": "Java" } ] } [/block] [block:callout] { "type": "warning", "title": "Optional", "body": "In case you are loading the data before using it, follow these two steps:" } [/block] A) Get the selected state index of a case. [block:code] { "codes": [ { "code": "int index = [ElastiCode stateIndexWithoutVisitForCase:@\"Buy Button\"];", "language": "objectivec" }, { "code": "let index = ElastiCode .stateIndexWithoutVisitForCase(\"Buy Button\")", "language": "objectivec", "name": "Swift" }, { "code": "int stateIndex = elasticode.stateIndexWithoutVisitForCase(\"Buy Button\");", "language": "java", "name": "Java" } ] } [/block] B) Once a case is visible to an end user, alert our server about it: [block:parameters] { "data": { "h-0": "Key", "h-1": "Type", "h-2": "Description/Example", "0-0": "caseName", "0-1": "String", "0-2": "Name of the relevant case you would like to alert about" }, "cols": 3, "rows": 1 } [/block] [block:code] { "codes": [ { "code": "[ElastiCode visitCase:@\"Buy Button\"];", "language": "objectivec" }, { "code": "ElastiCode .visitCase(\"Buy Button\")", "language": "objectivec", "name": "Swift" }, { "code": "elasticode.visitCase(\"Buy Button\");", "language": "java", "name": "Java" } ] } [/block] ##**Reaching a goal** In order to optimise your app, we need to know what the desired action of each case is, and understand the conversion rate for each alternative. The desired action should be defined within the code, by the developer and may be a click (e.g. on the “buy" button), a swipe or even the fact that a user had not left the screen for 2 minutes (if you aim for retention). To notify Elasticode regarding a successful action: [block:code] { "codes": [ { "code": "[ElastiCode goalReached:@\"Buy Button\"];", "language": "objectivec" }, { "code": "ElastiCode .goalReached(\"Buy Button\")", "language": "objectivec", "name": "Swift" }, { "code": "elasticode.goalReached(\"Buy Button\");", "language": "java", "name": "Java" } ] } [/block]