Actions
Create a Data Collection Action
note this legacy flow remains supported for backward compatibility new integrations are recommended to use the context layer–based getactions() approach https //app archbee com/docs/gi3o1i4xddy584dqsyxqi/draft fgdkril 90o1tvmcnlh #fmkdd 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 https //docs monetate com/docs/available omnichannel action types#omni data collect action you can set up a handler for a data collection action by using two methods the docid\ f5siejxas3hi38daxdvpy method defines the events that can trigger the action the docid\ f5siejxas3hi38daxdvpy 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(); data collection action usng contextlayer note the context based getactions() flow replaces the need to manually use addevent and getactionsdata when evaluating actions supported sdk version android 1 0 6 a or later ios 2026 01 06 or later using the new context layer–based approach , datacollection actions can be implemented using a single enhanced getactions() method below is the sample code snippet demonstrating this usage for detailed information on the enhanced getactions() flow, please refer to the https //app archbee com/docs/gi3o1i4xddy584dqsyxqi/draft dylopo9otr0siaobjo tg#mdskq and https //app archbee com/docs/gi3o1i4xddy584dqsyxqi/draft hu vwvf805c jlvv0fa6m sections code example getactionsdata example public func getactions(context\ contextobj,requestid string,arractiontypes \[string],includereporting bool) getactionsdata example public void getactions(final context context,final string\[] actiontypes,final boolean includereports,final actionscallback actionscallback)() full code exmaple data collection action full example //setting up context data let contextobj = contextobj() contextobj addipaddress("1 0 0 0") contextobj addpagedetails(pagetype "pdp", path "n/a", url "n/a", categories \[], breadcrumbs \[]) contextobj addscreensizedata(screenheight 1000, screenwidth 400) //request datacollection action data objpersonalization getactions(context contextobj, requestid "test request id", arractiontypes \["monetate\ action\ omnichannelrecommendation"], includereporting false) on(success { (actions) in self handlerecommendations(actions actions) }) } data collection action full example //setting up context data context context = new context(); context addipaddress("1 0 0 0"); 	 context addscreensizedata(1010, 2121); context addpagedetails("homepage", "https //www monetate com", new string\[] {"categories here"},new string\[] {"breadcrums here"},"test/path"); //request datacollection action data 	 personalization getactions(context, new string\[] {"monetate\ action\ datacollection"}, false,new actionscallback() { 	@override 	public void onsuccess(string actions) { 	 //prints the actions data received here 	 system out println("action data "+actions); 	} 	 	@override 	public void onerror(exception e) { 	 //prints the error/exception data here 	 system out println("ex "+e); 	} });