Event Code Samples
Android Event Code Samples
the following events are available to use in the android version of the monetate sdk metadata event contextmetadata event code example personalization personalization = new personalization(user, account); metadata data = new metadata(); data setmetadata(new language("inr")); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes contextmetadata, data); } }) start(); screen size event contextscreensize event code example personalization personalization = new personalization(user, account); screensize screensize = new screensize(); screensize setheight(1211); screensize setwidth(2323); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes contextscreensize, screensize); } }) start(); user agent event imports useragent data from the device this data represents information about the device of the customer contextuseragent event code example personalization personalization = new personalization(user, account); personalization report(eventtypes contextuseragent, new useragent("test agent")); personalization personalization = new personalization(user, account); public devicedetails getdata() { devicedetails devicedetails = new devicedetails(); devicedetails setdevice(build device); devicedetails setmodel(build model); devicedetails setproductname(build brand); devicedetails setosversion(system getproperty("os version")); devicedetails setosapilevel(build version release + "(" + build version sdk int + ")"); return devicedetails; } devicedetails details = getdata(); string data = personalization refactordevicedetails(details); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes contextuseragent, new useragent(data)); } }) start(); product view event contextproductview event code example personalization personalization = new personalization(user, account); productview productview = new productview(); productview\ setproducts(new string\[] { "product1", "product2" }); //passing raw data while reporting event new thread(new runnable() { @override public void run() { personalization report(eventtypes contextproductview, productview); } }) start(); coordinates event reports the coordinates of the customer contextcoordinates event code example personalization personalization = new personalization(user, account); coordinates coordinates = new coordinates(); coordinates setlatitude("1212"); coordinates setlongitude("2323"); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes contextcoordinates, coordinates); } }) start(); referrer event reports the referrer contextreferrer event code example personalization personalization = new personalization(user, account); referrer referrer = new referrer(); referrer setreferrer("test com"); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes contextreferrer, referrer); } }) start(); custom variable event contextcustomvariables event code example personalization personalization = new personalization(user, account); customvariable customvariable = new customvariable(); customvariable setvalue("key"); customvariable setvariable("value"); customvariables customvariables = new customvariables(); customvariables setcustomvariables(new customvariable\[] { customvariable }); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes contextcustomvariables, customvariables); } }) start(); pageevents event reports any events on the page pageevents event code example personalization personalization = new personalization(user, account); pageevents pageevents = new pageevents(); pageevents setpageevents(new string\[] { "pageevent 1", "pageevent 2" }); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes recordpageevents, pageevents); } }) start(); page view event reports when a customer views a specified page contextpageview event code example personalization personalization = new personalization(user, account); pageview pageview = new pageview(); pageview\ setbreadcrumbs(new string\[] { "breadcrums 1", "breadcrums 2", "breadcrums 3" }); pageview\ setcategories(new string\[] { "category 1", "category 2" }); pageview\ setpagetype("home page"); pageview\ seturl("na"); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes contextpageview, pageview); } }) start(); product thumbnail event reports when a customer views a product thumbnail contextproductthumbnailview event code example personalization personalization = new personalization(user, account); productthumbnailview productthumbnailview = new productthumbnailview(); productthumbnailview\ setproducts(new string\[] { "product1", "product2", "product3" }); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes contextproductthumbnailview, productthumbnailview); } }) start(); product detail view event reports when a customer views a product detail page contextproductdetailview event code example personalization personalization = new personalization(user, account); product product 111 = new product(); product 111 setproductid("pid 111"); product 111 setsku("sku 111"); product product 222 = new product(); product 222 setproductid("pid 222"); product 222 setsku("sku 222"); productdetailview detailview = new productdetailview(); detailview\ setproducts(new product\[] { product 111, product 222 }); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes contextproductdetailview, detailview); } }) start(); recommendation clicks event reports recommendations click events recordrecclicks event code example personalization personalization = new personalization(user, account); recclicks recclicks = new recclicks(); recclicks setrecclicks(new string\[] { "test recclick 1", "test recclick 2" }); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes recordrecclicks, recclicks); } }) start(); recommendation impressions event reports recommendations impression events recordrecimpressions event code example personalization personalization = new personalization(user, account); recimpressions recimpressions = new recimpressions(); recimpressions setrecimpressions(new string\[] { "test rec imp 1", "test rec imp 2" }); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes recordrecimpressions, recimpressions); } }) start(); impressions event reports impression events recordimpressions event code example personalization personalization = new personalization(user, account); impressions impressions = new impressions(); impressions setimpressionids(new string\[] { "testimpressionsid1", "testimpressionsid2" }); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes recordimpressions, impressions); } }) start(); cart event reports when a customer adds a product to their cart import and use the cartlinesdata interface for this event cartline is the data structure used by this interface contextcart event code example personalization personalization = new personalization(user, account); cartline cartline = new cartline(); cartline setcurrency("inr"); cartline setpid("pid"); cartline setquantity(2); cartline setsku("sku"); cartline setunitprice("000"); cartline setvalue("11"); cartline cartline2 = new cartline(); cartline2 setcurrency("usa"); cartline2 setpid("pid"); cartline2 setquantity(2); cartline2 setsku("sku"); cartline2 setunitprice("9999"); cartline2 setvalue("111"); cart cart = new cart(); cart setcartlines(new cartline\[] { cartline, cartline2 }); // passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes contextcart, cart); } }) start(); add to cart event contextaddtocart event code example personalization personalization = new personalization(user, account); cartline cartline = new cartline(); cartline setcurrency("inr"); cartline setpid("pid"); cartline setquantity(2); cartline setsku("sku"); cartline setvalue("11"); cartline cartline2 = new cartline(); cartline2 setcurrency("usa"); cartline2 setpid("pid"); cartline2 setquantity(2); cartline2 setsku("sku"); cartline2 setvalue("111"); addtocart addtocart = new addtocart(); addtocart setcartlines(new cartline\[] { cartline, cartline2 }); new thread(new runnable() { @override public void run() { personalization report(eventtypes contextaddtocart, addtocart); } }) start(); ipaddress event contextipaddress event code example personalization personalization = new personalization(user, account); ipaddress address = new ipaddress(); address setipaddress("127 0 0 0 "); //passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes contextipaddress, address); } }) start(); purchase event contextpurchase event code example personalization personalization = new personalization(user, account); purchaseline line = new purchaseline(); line setcurrency("inr"); line setpid("pid"); line setquantity(2); line setsku("sku"); line setvalue("12 00"); purchase purchase = new purchase(); purchase setpurchaselines(new purchaseline\[] { line }); purchase setaccount("tes account"); purchase setdomain("test domain"); purchase setinstance("test instance"); purchase setpurchaseid("test purchase id"); //passing raw data while reporting new thread(new runnable() { @override public void run() { personalization report(eventtypes contextpurchase, purchase); } }) start();