Event Code Samples
Android Event Code Samples
The following events are available to use in the Android version of the Monetate SDK.
ContextMetadata Event Code Example
1Personalization personalization = new Personalization(user, account);
2
3MetaData data = new MetaData();
4data.setMetadata(new Language("INR"));
5
6// Passing raw data while reporting
7new Thread(new Runnable()
8{
9 @Override
10 public void run()
11 {
12 personalization.report(EventTypes.ContextMetadata, data);
13 }
14}).start();
ContextScreenSize Event Code Example
1Personalization personalization = new Personalization(user, account);
2ScreenSize screenSize = new ScreenSize();
3screenSize.setHeight(1211);
4screenSize.setWidth(2323);
5
6// Passing raw data while reporting
7new Thread(new Runnable()
8{
9 @Override
10 public void run()
11 {
12 personalization.report(EventTypes.ContextScreenSize, screenSize);
13 }
14}).start();
Imports UserAgent data from the device. This data represents information about the device of the customer.
ContextUserAgent Event Code Example
1Personalization personalization = new Personalization(user, account);
2
3personalization.report(EventTypes.ContextUserAgent, new UserAgent("test_agent"));
4
5Personalization personalization = new Personalization(user, account);
6
7public DeviceDetails getData()
8{
9 DeviceDetails deviceDetails = new DeviceDetails();
10 deviceDetails.setDevice(Build.DEVICE);
11 deviceDetails.setModel(Build.MODEL);
12 deviceDetails.setProductName(Build.BRAND);
13 deviceDetails.setOsVersion(System.getProperty("os.version"));
14 deviceDetails.setOsApiLevel(Build.VERSION.RELEASE + "(" + Build.VERSION.SDK_INT + ")");
15 return deviceDetails;
16}
17
18DeviceDetails details = getData();
19
20String data = personalization.refactorDeviceDetails(details);
21
22// Passing raw data while reporting
23new Thread(new Runnable()
24{
25 @Override
26 public void run()
27 {
28 personalization.report(EventTypes.ContextUserAgent, new UserAgent(data));
29 }
30}).start();
ContextProductView Event Code Example
1Personalization personalization = new Personalization(user, account);
2
3ProductView productView = new ProductView();
4productView.setProducts(new String[]
5{
6 "product1",
7 "product2"
8});
9
10//passing raw data while reporting event
11new Thread(new Runnable()
12{
13 @Override
14 public void run()
15 {
16 personalization.report(EventTypes.ContextProductView, productView);
17 }
18}).start();
Reports the coordinates of the customer.
ContextCoordinates Event Code Example
1Personalization personalization = new Personalization(user, account);
2Coordinates coordinates = new Coordinates();
3coordinates.setLatitude("1212");
4coordinates.setLongitude("2323");
5
6// Passing raw data while reporting
7new Thread(new Runnable()
8{
9 @Override
10 public void run()
11 {
12 personalization.report(EventTypes.ContextCoordinates, coordinates);
13 }
14}).start();
Reports the referrer.
ContextReferrer Event Code Example
1Personalization personalization = new Personalization(user, account);
2
3Referrer referrer = new Referrer();
4referrer.setReferrer("test.com");
5
6// Passing raw data while reporting
7new Thread(new Runnable()
8{
9 @Override
10 public void run()
11 {
12 personalization.report(EventTypes.ContextReferrer, referrer);
13 }
14}).start();
ContextCustomVariables Event Code Example
1Personalization personalization = new Personalization(user, account);
2CustomVariable customVariable = new CustomVariable();
3customVariable.setValue("key");
4customVariable.setVariable("value");
5
6CustomVariables customVariables = new CustomVariables();
7customVariables.setCustomVariables(new CustomVariable[]
8{
9 customVariable
10});
11
12// Passing raw data while reporting
13new Thread(new Runnable()
14{
15 @Override
16 public void run()
17 {
18 personalization.report(EventTypes.ContextCustomVariables, customVariables);
19 }
20}).start();
Reports any events on the page.
PageEvents Event Code Example
1Personalization personalization = new Personalization(user, account);
2
3PageEvents pageEvents = new PageEvents();
4pageEvents.setPageEvents(new String[]
5{
6 "pageEvent_1",
7 "pageEvent_2"
8});
9
10// Passing Raw data while reporting
11new Thread(new Runnable()
12{
13 @Override
14 public void run()
15 {
16 personalization.report(EventTypes.RecordPageEvents, pageEvents);
17 }
18}).start();
Reports when a customer views a specified page.
ContextPageView Event Code Example
1Personalization personalization = new Personalization(user, account);
2
3PageView pageView = new PageView();
4pageView.setBreadcrumbs(new String[]
5{
6 "breadcrums_1",
7 "breadcrums_2",
8 "breadcrums_3"
9});
10pageView.setCategories(new String[]
11{
12 "category_1",
13 "category_2"
14});
15pageView.setPageType("home_page");
16pageView.setUrl("NA");
17
18// Passing raw data while reporting
19new Thread(new Runnable()
20{
21 @Override
22 public void run()
23 {
24 personalization.report(EventTypes.ContextPageView, pageView);
25 }
26}).start();
Reports when a customer views a product thumbnail.
ContextProductThumbnailView Event Code Example
1Personalization personalization = new Personalization(user, account);
2
3ProductThumbnailView productThumbnailView = new ProductThumbnailView();
4productThumbnailView.setProducts(new String[]
5{
6 "product1",
7 "product2",
8 "product3"
9});
10
11// Passing raw data while reporting
12new Thread(new Runnable()
13{
14 @Override
15 public void run()
16 {
17 personalization.report(EventTypes.ContextProductThumbnailView, productThumbnailView);
18 }
19}).start();
Reports when a customer views a product detail page.
ContextProductDetailView Event Code Example
1Personalization personalization = new Personalization(user, account);
2Product product_111 = new Product();
3product_111.setProductId("PID_111");
4product_111.setSku("SKU_111");
5
6Product product_222 = new Product();
7product_222.setProductId("PID_222");
8product_222.setSku("SKU_222");
9
10ProductDetailView detailView = new ProductDetailView();
11detailView.setProducts(new Product[]
12{
13 product_111,
14 product_222
15});
16
17// Passing raw data while reporting
18new Thread(new Runnable()
19{
20 @Override
21 public void run()
22 {
23 personalization.report(EventTypes.ContextProductDetailView, detailView);
24 }
25}).start();
Reports recommendations click events.
RecordRecClicks Event Code Example
1Personalization personalization = new Personalization(user, account);
2
3RecClicks recClicks = new RecClicks();
4recClicks.setRecClicks(new String[]
5{
6 "test_recclick_1",
7 "test_recclick_2"
8});
9
10// Passing raw data while reporting
11new Thread(new Runnable()
12{
13 @Override
14 public void run()
15 {
16 personalization.report(EventTypes.RecordRecClicks, recClicks);
17 }
18}).start();
Reports recommendations impression events.
RecordRecImpressions Event Code Example
1Personalization personalization = new Personalization(user, account);
2
3RecImpressions recimpressions = new RecImpressions();
4recimpressions.setRecImpressions(new String[]
5{
6 "test_rec_imp_1",
7 "test_rec_imp_2"
8});
9
10
11// Passing raw data while reporting
12new Thread(new Runnable()
13{
14
15 @Override
16 public void run()
17 {
18 personalization.report(EventTypes.RecordRecImpressions, recimpressions);
19 }
20}).start();
Reports impression events.
RecordImpressions Event Code Example
1Personalization personalization = new Personalization(user, account);
2Impressions impressions = new Impressions();
3impressions.setimpressionIds(new String[]
4{
5 "testimpressionsId1",
6 "testimpressionsId2"
7});
8
9// Passing raw data while reporting
10new Thread(new Runnable()
11{
12 @Override
13 public void run()
14 {
15 personalization.report(EventTypes.RecordImpressions, impressions);
16 }
17}).start();
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
1Personalization personalization = new Personalization(user, account);
2
3CartLine cartLine = new CartLine();
4cartLine.setCurrency("INR");
5cartLine.setPid("PID");
6cartLine.setQuantity(2);
7cartLine.setSku("SKU");
8cartLine.setUnitPrice("000");
9cartLine.setValue("11");
10
11CartLine cartLine2 = new CartLine();
12cartLine2.setCurrency("USA");
13cartLine2.setPid("PID");
14cartLine2.setQuantity(2);
15cartLine2.setSku("SKU");
16cartLine2.setUnitPrice("9999");
17cartLine2.setValue("111");
18
19Cart cart = new Cart();
20cart.setCartLines(new CartLine[]
21{
22 cartLine,
23 cartLine2
24});
25
26// Passing raw data while reporting
27new Thread(new Runnable()
28{
29 @Override
30 public void run()
31 {
32 personalization.report(EventTypes.ContextCart, cart);
33 }
34}).start();
ContextAddToCart Event Code Example
1Personalization personalization = new Personalization(user, account);
2
3CartLine cartLine = new CartLine();
4cartLine.setCurrency("INR");
5cartLine.setPid("PID");
6cartLine.setQuantity(2);
7cartLine.setSku("SKU");
8cartLine.setValue("11");
9
10CartLine cartLine2 = new CartLine();
11cartLine2.setCurrency("USA");
12cartLine2.setPid("PID");
13cartLine2.setQuantity(2);
14cartLine2.setSku("SKU");
15cartLine2.setValue("111");
16
17AddToCart addToCart = new AddToCart();
18addToCart.setCartLines(new CartLine[]
19{
20 cartLine,
21 cartLine2
22});
23
24new Thread(new Runnable()
25{
26 @Override
27 public void run()
28 {
29 personalization.report(EventTypes.ContextAddToCart, addToCart);
30 }
31}).start();
ContextIpAddress Event Code Example
1Personalization personalization = new Personalization(user, account);
2
3IpAddress address = new IpAddress();
4address.setIpAddress("127.0.0.0.");
5
6//passing raw data while reporting
7new Thread(new Runnable()
8{
9 @Override
10 public void run()
11 {
12 personalization.report(EventTypes.ContextIpAddress, address);
13 }
14}).start();
ContextClosedSession Event Code Example
1Personalization personalization = new Personalization(user, account);
2
3ClosedSession closedSession = new ClosedSession();
4closedSession.setClosedSession(new com.monetate.personalization.androidsdk.model.objects.ClosedSession("test_id"));
5closedSession.setVersion("test_version");
6
7// Passing raw data while reporting
8new Thread(new Runnable()
9{
10 @Override
11 public void run()
12 {
13 personalization.report(EventTypes.ContextClosedSession, closedSession);
14 }
15}).start();
ContextPurchase Event Code Example
1Personalization personalization = new Personalization(user, account);
2PurchaseLine line = new PurchaseLine();
3line.setCurrency("INR");
4line.setPid("PID");
5line.setQuantity(2);
6line.setSku("SKU");
7line.setValue("12.00");
8
9Purchase purchase = new Purchase();
10purchase.setPurchaseLines(new PurchaseLine[]
11{
12 line
13});
14purchase.setAccount("tes_account");
15purchase.setDomain("test_domain");
16purchase.setInstance("test_instance");
17purchase.setPurchaseId("test_purchase_id");
18
19//passing raw data while reporting
20new Thread(new Runnable()
21{
22
23 @Override
24 public void run()
25 {
26 personalization.report(EventTypes.ContextPurchase, purchase);
27 }
28}).start();