{"__v":5,"_id":"562014128a05d7230006ffda","category":{"__v":1,"_id":"562014108a05d7230006ffae","pages":["562014128a05d7230006ffd8","562014128a05d7230006ffd9","562014128a05d7230006ffda","562014128a05d7230006ffdb","562014128a05d7230006ffdc","562014128a05d7230006ffdd","562014128a05d7230006ffde","562014128a05d7230006ffdf","562014128a05d7230006ffe0","562014128a05d7230006ffe1","562014128a05d7230006ffe2","562014128a05d7230006ffe3","562014128a05d7230006ffe4","562014128a05d7230006ffe5"],"project":"54861bb654b3ce0b00367292","version":"5620140f8a05d7230006ffac","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2014-12-08T22:54:31.828Z","from_sync":false,"order":2,"slug":"2-personalization","title":"Cases & Dynamic Objects"},"parentDoc":null,"project":"54861bb654b3ce0b00367292","user":"54861b9f3681d914006992a4","version":{"__v":3,"_id":"5620140f8a05d7230006ffac","project":"54861bb654b3ce0b00367292","createdAt":"2015-10-15T21:01:03.908Z","releaseDate":"2015-10-15T21:01:03.908Z","categories":["562014108a05d7230006ffad","562014108a05d7230006ffae","562014108a05d7230006ffaf","562014108a05d7230006ffb0","562014108a05d7230006ffb1","562014108a05d7230006ffb2","562014108a05d7230006ffb3","562014108a05d7230006ffb4","562014108a05d7230006ffb5","5666f7f5d784a70d00397bff","56967935b6d61f0d00acfb0b"],"is_deprecated":true,"is_hidden":false,"is_beta":false,"is_stable":false,"codename":"Moments","version_clean":"2.0.0","version":"2.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2014-12-09T10:39:35.955Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"never","params":[],"url":""},"isReference":false,"order":2,"body":"##**Defining the Dynamic Objects** - Setting dashboard-controlled dynamic elements\nThe developer should define the dynamic object by:  \na) Name  \nb) Type  \nc) Default value\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Key\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description/Example\",\n    \"0-0\": \"dObjName\",\n    \"0-1\": \"String\",\n    \"0-2\": \"Indicating the name of the dynamic object you are defining, for example: \\\"Button Color\\\"\",\n    \"1-0\": \"dObjType\",\n    \"1-1\": \"ElastiCodeDObjType*\",\n    \"1-2\": \"Type of the dynamic object - comment below\",\n    \"2-0\": \"defaultValue\",\n    \"2-1\": \"iOS - NSObject \\n\\nSwift - AnyObject \\n\\nJava - Object\",\n    \"2-2\": \"Default value that will be used in case of error An object relevant to the dObjType\"\n  },\n  \"cols\": 3,\n  \"rows\": 3\n}\n[/block]\n* ElastiCodeDObjType has to be set as a single or multi value object (an array)\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"**iOS/Swift -** ElastiCodeDObjType_bool \\n\\n**Java -** ElastiCodeDObjType.BOOLEAN\",\n    \"0-1\": \"**iOS** - NSNumber \\n\\n**Swift** - bool\\n\\n**Android** - Boolean\",\n    \"0-2\": \"Boolean value, ie. true\",\n    \"h-0\": \"Key\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description/Example\",\n    \"1-0\": \"**iOS/Swift - **ElastiCodeDObjType_int\\n\\n**Java - **ElastiCodeDObjType.INTEGER\",\n    \"1-1\": \"**iOS** - NSNumber \\n\\n**Swift** - Integer\\n\\n**Android** - Integer\",\n    \"1-2\": \"Integer value, i. e. 100\",\n    \"2-0\": \"**iOS/Swift - **ElastiCodeDObjType_double\\n\\n**Java - **ElastiCodeDObjType.DOUBLE\",\n    \"2-1\": \"**iOS** - NSNumber \\n\\n**Swift** - Double\\n\\n**Android** - Double\",\n    \"2-2\": \"Double value, i. e. 3.14\",\n    \"3-0\": \"**iOS/Swift - **ElastiCodeDObjType_string\\n\\n**Java - **ElastiCodeDObjType.STRING\",\n    \"3-1\": \"**iOS** - NSString \\n\\n**Swift** - String\\n\\n**Android** - String\",\n    \"3-2\": \"String value, i.e. \\\"Welcome!\\\"\"\n  },\n  \"cols\": 3,\n  \"rows\": 4\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"A quick note before we move on... We can use dynamic objects ONLY after sync\",\n  \"body\": \"Remember, you could only use the personalization capability of dynamic objects only after the sync was finished.\"\n}\n[/block]\n##Array of ... \n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Key\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description/Example\",\n    \"0-0\": \"**iOS/Swift - **ElastiCodeDObjType_arrayOfBool\\n\\n**Java - **ElastiCodeDObjType.ARRAY_OF_BOOLEAN\",\n    \"0-1\": \"**iOS** - NSArray \\n\\n**Swift** - [Bool]\\n\\n**Android** - String\",\n    \"0-2\": \"Boolean values ( array of  )\",\n    \"1-0\": \"**iOS/Swift - **ElastiCodeDObjType_arrayOfInt\\n\\n**Java - **ElastiCodeDObjType.ARRAY_OF_INTEGER\",\n    \"2-0\": \"**iOS/Swift - **ElastiCodeDObjType_arrayOfDouble\\n\\n**Java - **ElastiCodeDObjType.ARRAY_OF_DOUBLE\",\n    \"3-0\": \"**iOS/Swift - **ElastiCodeDObjType_arrayOfString\\n\\n**Java - **ElastiCodeDObjType.ARRAY_OF_STRING\",\n    \"1-1\": \"**iOS** - NSArray \\n\\n**Swift** - [Integer]\\n\\n**Android** - String\",\n    \"2-1\": \"**iOS** - NSArray \\n\\n**Swift** - [Double]\\n\\n**Android** - String\",\n    \"3-1\": \"**iOS** - NSArray \\n\\n**Swift** - [String]\\n\\n**Android** - String\",\n    \"1-2\": \"Integer values ( array of  )\",\n    \"2-2\": \"Double values ( array of  )\",\n    \"3-2\": \"String values ( array of  )\"\n  },\n  \"cols\": 3,\n  \"rows\": 4\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Before \\\"starting a session\\\"\",\n  \"body\": \"This method should be initiated before starting a new session\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[ElastiCode defineDynamicObject::::at:::\\\"foodTypes\\\"\\n \\ttype:ElastiCodeDObjType_arrayOfString \\n \\tdefaultValue:@[@\\\"BBQ\\\", @\\\"Healthy food\\\", @\\\"Snacks\\\"]\\n];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"var foodTypes: [String] = [\\\"BBQ\\\", \\\"Healthy food\\\", \\\"Snacks\\\"]\\n \\nElastiCode .defineDynamicObject(\\\"foodTypes\\\", \\n                                type: ElastiCodeDObjType_arrayOfString, \\n                                defaultValue: foodTypes)\",\n      \"language\": \"objectivec\",\n      \"name\": \"Swift\"\n    }\n  ]\n}\n[/block]\n##**Value Per Dynamic Object**\nOnce you want to use the dynamic object value, call  valueForDynamicObject method that retrieves the relevant value, The object’s value will be set by you in our dashboard or will be the one you set as a default.\n\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Key\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description/Example\",\n    \"0-0\": \"dObjName\",\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\": \"NSObject* value = [ElastiCode valueForDynamicObject:@\\\"Page Title\\\"];\\nif(value){\\n  label.text = (NSString*)value;\\n}\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"let value: AnyObject? = ElastiCode .valueForDynamicObject(\\\"Page Title\\\")\\nlabel.text = value! as? NSString;\",\n      \"language\": \"objectivec\",\n      \"name\": \"Swift\"\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\": \"NSObject* value = [ElastiCode valueWithoutVisitForDynamicObject:@\\\"Page Title\\\"];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"let value = ElastiCode .valueWithoutVisitForDynamicObject(\\\"Page Title\\\")\",\n      \"language\": \"objectivec\",\n      \"name\": \"Swift\"\n    }\n  ]\n}\n[/block]\nB) Once a case is visible to an end user, alert our server about it:\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Key\",\n    \"h-1\": \"Type\",\n    \"h-2\": \"Description/Example\",\n    \"0-0\": \"dObjName\",\n    \"0-1\": \"String\",\n    \"0-2\": \"Name of the relevant object 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 visitDynamicObject:@\\\"Page Title\\\"];\",\n      \"language\": \"objectivec\",\n      \"name\": null\n    },\n    {\n      \"code\": \"ElastiCode .visitDynamicObject(\\\"Page Title\\\")\",\n      \"language\": \"objectivec\",\n      \"name\": \"Swift\"\n    }\n  ]\n}\n[/block]\n##**Reaching a goal**\nIn order to optimise your app we need to know what is the desired action of each dynamic object and from that to understand the conversion rate of each alternative. \nThe desired action should be defined within the code by the developer and may be a click (e.g. for the “Buy button”), \na swipe or even the fact that a user had not left the screen for 2 minutes (if you desire for retention). \nAs said, it can be anything of your choice...\n\nTo update elasticode about a successful action, use:\n\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"[ElastiCode dynamicObjectGoalReached:@\\\"Buy Button\\\"];\",\n      \"language\": \"objectivec\"\n    },\n    {\n      \"code\": \"ElastiCode .dynamicObjectGoalReached(\\\"Buy Button\\\")\",\n      \"language\": \"objectivec\",\n      \"name\": \"Swift\"\n    }\n  ]\n}\n[/block]","excerpt":"Building dynamic objects, their default values, visits and actions","slug":"creating-dynamic-objects","type":"basic","title":"Creating Dynamic objects"}

Creating Dynamic objects

Building dynamic objects, their default values, visits and actions

##**Defining the Dynamic Objects** - Setting dashboard-controlled dynamic elements The developer should define the dynamic object by: a) Name b) Type c) Default value [block:parameters] { "data": { "h-0": "Key", "h-1": "Type", "h-2": "Description/Example", "0-0": "dObjName", "0-1": "String", "0-2": "Indicating the name of the dynamic object you are defining, for example: \"Button Color\"", "1-0": "dObjType", "1-1": "ElastiCodeDObjType*", "1-2": "Type of the dynamic object - comment below", "2-0": "defaultValue", "2-1": "iOS - NSObject \n\nSwift - AnyObject \n\nJava - Object", "2-2": "Default value that will be used in case of error An object relevant to the dObjType" }, "cols": 3, "rows": 3 } [/block] * ElastiCodeDObjType has to be set as a single or multi value object (an array) [block:parameters] { "data": { "0-0": "**iOS/Swift -** ElastiCodeDObjType_bool \n\n**Java -** ElastiCodeDObjType.BOOLEAN", "0-1": "**iOS** - NSNumber \n\n**Swift** - bool\n\n**Android** - Boolean", "0-2": "Boolean value, ie. true", "h-0": "Key", "h-1": "Type", "h-2": "Description/Example", "1-0": "**iOS/Swift - **ElastiCodeDObjType_int\n\n**Java - **ElastiCodeDObjType.INTEGER", "1-1": "**iOS** - NSNumber \n\n**Swift** - Integer\n\n**Android** - Integer", "1-2": "Integer value, i. e. 100", "2-0": "**iOS/Swift - **ElastiCodeDObjType_double\n\n**Java - **ElastiCodeDObjType.DOUBLE", "2-1": "**iOS** - NSNumber \n\n**Swift** - Double\n\n**Android** - Double", "2-2": "Double value, i. e. 3.14", "3-0": "**iOS/Swift - **ElastiCodeDObjType_string\n\n**Java - **ElastiCodeDObjType.STRING", "3-1": "**iOS** - NSString \n\n**Swift** - String\n\n**Android** - String", "3-2": "String value, i.e. \"Welcome!\"" }, "cols": 3, "rows": 4 } [/block] [block:callout] { "type": "info", "title": "A quick note before we move on... We can use dynamic objects ONLY after sync", "body": "Remember, you could only use the personalization capability of dynamic objects only after the sync was finished." } [/block] ##Array of ... [block:parameters] { "data": { "h-0": "Key", "h-1": "Type", "h-2": "Description/Example", "0-0": "**iOS/Swift - **ElastiCodeDObjType_arrayOfBool\n\n**Java - **ElastiCodeDObjType.ARRAY_OF_BOOLEAN", "0-1": "**iOS** - NSArray \n\n**Swift** - [Bool]\n\n**Android** - String", "0-2": "Boolean values ( array of )", "1-0": "**iOS/Swift - **ElastiCodeDObjType_arrayOfInt\n\n**Java - **ElastiCodeDObjType.ARRAY_OF_INTEGER", "2-0": "**iOS/Swift - **ElastiCodeDObjType_arrayOfDouble\n\n**Java - **ElastiCodeDObjType.ARRAY_OF_DOUBLE", "3-0": "**iOS/Swift - **ElastiCodeDObjType_arrayOfString\n\n**Java - **ElastiCodeDObjType.ARRAY_OF_STRING", "1-1": "**iOS** - NSArray \n\n**Swift** - [Integer]\n\n**Android** - String", "2-1": "**iOS** - NSArray \n\n**Swift** - [Double]\n\n**Android** - String", "3-1": "**iOS** - NSArray \n\n**Swift** - [String]\n\n**Android** - String", "1-2": "Integer values ( array of )", "2-2": "Double values ( array of )", "3-2": "String values ( array of )" }, "cols": 3, "rows": 4 } [/block] [block:callout] { "type": "warning", "title": "Before \"starting a session\"", "body": "This method should be initiated before starting a new session" } [/block] [block:code] { "codes": [ { "code": "[ElastiCode defineDynamicObject:@\"foodTypes\"\n \ttype:ElastiCodeDObjType_arrayOfString \n \tdefaultValue:@[@\"BBQ\", @\"Healthy food\", @\"Snacks\"]\n];", "language": "objectivec" }, { "code": "var foodTypes: [String] = [\"BBQ\", \"Healthy food\", \"Snacks\"]\n \nElastiCode .defineDynamicObject(\"foodTypes\", \n type: ElastiCodeDObjType_arrayOfString, \n defaultValue: foodTypes)", "language": "objectivec", "name": "Swift" } ] } [/block] ##**Value Per Dynamic Object** Once you want to use the dynamic object value, call valueForDynamicObject method that retrieves the relevant value, The object’s value will be set by you in our dashboard or will be the one you set as a default. [block:parameters] { "data": { "h-0": "Key", "h-1": "Type", "h-2": "Description/Example", "0-0": "dObjName", "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": "NSObject* value = [ElastiCode valueForDynamicObject:@\"Page Title\"];\nif(value){\n label.text = (NSString*)value;\n}", "language": "objectivec" }, { "code": "let value: AnyObject? = ElastiCode .valueForDynamicObject(\"Page Title\")\nlabel.text = value! as? NSString;", "language": "objectivec", "name": "Swift" } ] } [/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": "NSObject* value = [ElastiCode valueWithoutVisitForDynamicObject:@\"Page Title\"];", "language": "objectivec" }, { "code": "let value = ElastiCode .valueWithoutVisitForDynamicObject(\"Page Title\")", "language": "objectivec", "name": "Swift" } ] } [/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": "dObjName", "0-1": "String", "0-2": "Name of the relevant object you would like to alert about" }, "cols": 3, "rows": 1 } [/block] [block:code] { "codes": [ { "code": "[ElastiCode visitDynamicObject:@\"Page Title\"];", "language": "objectivec", "name": null }, { "code": "ElastiCode .visitDynamicObject(\"Page Title\")", "language": "objectivec", "name": "Swift" } ] } [/block] ##**Reaching a goal** In order to optimise your app we need to know what is the desired action of each dynamic object and from that to understand the conversion rate of each alternative. The desired action should be defined within the code by the developer and may be a click (e.g. for the “Buy button”), a swipe or even the fact that a user had not left the screen for 2 minutes (if you desire for retention). As said, it can be anything of your choice... To update elasticode about a successful action, use: [block:code] { "codes": [ { "code": "[ElastiCode dynamicObjectGoalReached:@\"Buy Button\"];", "language": "objectivec" }, { "code": "ElastiCode .dynamicObjectGoalReached(\"Buy Button\")", "language": "objectivec", "name": "Swift" } ] } [/block]