---
title: Android Event Code Samples
slug: sdks/android-event-code
description: Code examples for the events available to use in the Android version of the Monetate SDK
image:  https://archbee-image-uploads.s3.amazonaws.com/ceIfEvQHzQk1IVxoRWUh7/K9eTL4jKm7UQINb6zNziJ-20250912-181225.png
docTags: 
createdAt: 2024-06-12T20:15:57.609Z
---

::::BlockQuote
**Note:**
&#x20;The code snippet below is supported **up to Android SDK version 1.0.5\@A**.

For **Android SDK version 1.0.6-A and later**, refer to:

:::Paragraph{listStyleType="disc" indent="1"}
**[Reporting Method](https://app.archbee.com/docs/gI3o1i4XdDy584dqSyxqi/DRAFT-3HHg9G943mGEOHt4Xq9yH)** section for reporting APIs&#x20;
:::

:::Paragraph{listStyleType="disc" listStart="2" indent="1"}
**[SDK Context Layer](https://app.archbee.com/docs/gI3o1i4XdDy584dqSyxqi/DRAFT-TzppVuxzLGq7dr27UlHyg)** section for other implementations
:::
::::


Metadata Event
--------------

:::CodeblockTabs
ContextMetadata Event Code Example

```javascript
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

:::CodeblockTabs
ContextScreenSize Event Code Example

```javascript
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.

:::CodeblockTabs
ContextUserAgent Event Code Example

```javascript
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

:::CodeblockTabs
ContextProductView Event Code Example

```javascript
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.

:::CodeblockTabs
ContextCoordinates Event Code Example

```javascript
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.

:::CodeblockTabs
ContextReferrer Event Code Example

```javascript
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

:::CodeblockTabs
ContextCustomVariables Event Code Example

```javascript
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.

:::CodeblockTabs
PageEvents Event Code Example

```javascript
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.

:::CodeblockTabs
ContextPageView Event Code Example

```javascript
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.

:::CodeblockTabs
ContextProductThumbnailView Event Code Example

```javascript
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.

:::CodeblockTabs
ContextProductDetailView Event Code Example

```javascript
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.

:::CodeblockTabs
RecordRecClicks Event Code Example

```javascript
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.

:::CodeblockTabs
RecordRecImpressions Event Code Example

```javascript
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.

:::CodeblockTabs
RecordImpressions Event Code Example

```javascript
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.

:::CodeblockTabs
ContextCart Event Code Example

```javascript
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

:::CodeblockTabs
ContextAddToCart Event Code Example

```javascript
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

:::CodeblockTabs
ContextIpAddress Event Code Example

```javascript
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

:::CodeblockTabs
ContextPurchase Event Code Example

```javascript
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();
```
:::

