Actions
Create a Data Collection Action
in some cases when you trigger an action, you might not want to alter your site's content while still retaining the customer data involved with the action in these cases, you can perform a data collect action you can set up a handler for a data collection action by using two methods the sdk methods method defines the events that can trigger the action the sdk methods method is then used as the trigger and requests the decision based on the defined events getactionsdata then returns a json object containing customer data while this data does not affect your site's content, you can use it for other cases elsewhere in code addevent this method adds a local event to the sdk's internal stack addevent method addevent(context eventtypes, events contextdata) void addevent method addevent(context eventtypes, events contextdata) void addevent method addevent(context \<contextenum>, event \<mevent?>) addevent method public void addevent(string context, object event) the parameters are as follows context is name of the event event is the event data you can use this method multiple times to add all the necessary events for an experience that you might want to trigger the example code uses multiple method calls to fulfill the experience requirements code example addevent example personalizationinstance addevent(eventtypes contextscreensize, { width 23, height 34 }); personalizationinstance addevent(eventtypes contextipaddress, { ipaddress "10 0 0 2", }); personalizationinstance addevent(eventtypes contextpageview, { url "http //www monetate com/index html", pagetype "home" }); addevent example personalizationinstance addevent(eventtypes contextscreensize, { width 23, height 34 }); personalizationinstance addevent(eventtypes contextipaddress, { ipaddress "10 0 0 2", }); personalizationinstance addevent(eventtypes contextpageview, { url "http //www monetate com/index html", pagetype "home" }); addevent example objpersonalization addevent(context pageview, event pageview(pagetype "homepage", path "n/a", url "n/a", categories \[], breadcrumbs \[])) addevent example personalization addevent(eventtypes contextipaddress, ipaddress); personalization addevent(eventtypes contextpageview, pageview); personalization addevent(eventtypes contextscreensize, screensize); getactionsdata this method sends the defined events to monetate to trigger an experience if the events fulfill the who settings of an experience, then that experience is triggered a json object containing the experience response is then returned getactionsdata method getactionsdata(actiontype array\<string>, includereporting boolean) promise\<any> the parameters are as follows actiontype is the type of action you want to request you can specify one action or multiple actions in an array to handle includereports indicates whether the response will have impression reporting data use datacollection as the action type for this method includereports must be set to true for this method to return data getactionsdata method getactionsdata(actiontype array\<string>, includereporting boolean) promise\<any> the parameters are as follows actiontype is the type of action you want to request you can specify one action or multiple actions in an array to handle includereports indicates whether the response will have impression reporting data use datacollection as the action type for this method includereports must be set to true for this method to return data getactionsdata method getactionsdata(requestid \<string>, includereporting \<bool>, arractiontypes <\[string]>) the parameters in the ios version are as follows requestid is the request id for the api includereporting indicates whether the response will have impression reporting data arractiontypes is the types of action you want to request you can specify multiple actions in an array to handle use datacollection as the action type for this method includereporting must be set to true for this method to return data getactionsdata method public string getactionsdata(string\[] actiontypes, boolean includereports) the parameters are as follows actiontype is the type of action you want to request you can specify one action or multiple actions in an array to handle includereports indicates whether the response will have impression reporting data use datacollection as the action type for this method includereports must be set to true for this method to return data code example getactionsdata example responsedata = personalizationinstance getactionsdata("monetate\ action\ datacollection", true); getactionsdata example responsedata = personalizationinstance getactionsdata("monetate\ action\ datacollection", true); getactionsdata example objpersonalization getactionsdata(requestid "123456", includereporting true, arractiontypes \["monetate\ action\ datacollection"]) on{res in if res status==200 { self handlerecommendations(res res) } else { } } } getactionsdata example string responsedata = personalization getactionsdata(new string\[]{"monetate\ action\ datacollection"},true); full code example data collection action full example // add context / events // personalizationinstance addevent(eventtypes contextscreensize, { width 23, height 34 }); personalizationinstance addevent(eventtypes contextipaddress, { ipaddress "10 0 0 2", }); personalizationinstance addevent(eventtypes contextpageview, { url "http //www monetate com/index html", pagetype "home" }); // // get actions let recdata; personalizationinstance getactionsdata("monetate\ action\ datacollection", true) then(res => { recsdata = res\[0] actions; }) catch(error => { console warn('error!', error); }); data collection action full example // add context / events // personalizationinstance addevent(eventtypes contextscreensize, { width 23, height 34 }); personalizationinstance addevent(eventtypes contextipaddress, { ipaddress "10 0 0 2", }); personalizationinstance addevent(eventtypes contextpageview, { url "http //www monetate com/index html", pagetype "home" }); // // get actions let recdata; personalizationinstance getactionsdata("monetate\ action\ datacollection", true) then(res => { recsdata = res\[0] actions; }) catch(error => { console warn('error!', error); }); data collection action full example import marqueelabel import uikit import monetate ios sdk class categoryviewcontroller uiviewcontroller { final var objpersonalization = personalization( account account( instance "p", domain "localhost org", name "a 701b337c", shortname "localhost"), user user(deviceid "62bd2e2d 213d 463f 83bb 12c0b2530a14")) override func viewdidload() { super viewdidload() } override func viewwillappear( animated bool) { super viewwillappear(animated) datacollectionevent() } func datacollectionevent() { objpersonalization addevent(context pageview, event pageview(pagetype "homepage", path "n/a", url "n/a", categories \[], breadcrumbs \[])) objpersonalization getactionsdata(requestid "test request id", includereporting true, arractiontypes \["monetate\ action\ datacollection"]) on { (res) in if res status == 200 { let data = json(res data) print(data) self handleaction(res res) } else { } } } } data collection action full example // events and context data ipaddress ipaddress = new ipaddress(); ipaddress setipaddress("1 0 0 0"); screensize screensize = new screensize(); screensize setheight(1011); screensize setwidth(2011); pageview pageview = new pageview(); pageview\ setpagetype("homepage"); pageview\ seturl("https //www monetate com"); // addevent personalization addevent(eventtypes contextipaddress, ipaddress); personalization addevent(eventtypes contextpageview, pageview); //getactionsdata string responsedata; new thread(new runnable() { @override public void run() { // gets the responsedata using getactionsdata responsedata = personalization getactions(eventtypes contextipaddress, address, new string\[] { "monetate\ action\ datacollection" }, true); // once you receive the responsedata from getactionsdata, use the handler and parse the required data from it new handler(looper getmainlooper()) post(new runnable() { @override public void run() { // parse the received responsedata, get the requireddata from it and use it accordingly try { // example textview\ settext(requireddata); } catch (exception ex) { // catch any exception that occurs while parsing ex printstacktrace(); } } }); } }) start();