# App Analytics SDK

## Prerequisites

1. Android Sample App&#x20;
2. MediaMelon SmartSight SDK  `appanalytics-release.aar`
3. MediaMelon-assigned Customer ID

{% hint style="info" %}
If you do not know your Customer ID contact MediaMelon at [support@mediamelon.com](mailto:support%40mediamelon.com)
{% endhint %}

## Step 1: Set up the build environment

1. Copy `appanalytics-release.aar` provided with the release package to `SampleApp/appanalytics-release.aar`
2. Add network permissions to

   `app/src/main/AndroidManifest.xml`

   ```
   <uses-permission android:name="android.permission.INTERNET"/>
   <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
   ```

## Step 2: Integrate MediaMelon SDK Code to SampleApp

The application must register the MediaMelon SDK and provide app information once when the application launches. Please note that values provided in this integration step persist across app sessions.

you need to create Application class `MyApplication.java`

```java
import android.app.Application;
import java.util.HashMap;
import com.mediamelon.appanalytics.MMIntegrationWrapper;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        ....
        MMIntegrationWrapper.getInstance(this).initialize("CUTOMER_ID" , "APP_NAME" , "APP_VERSION");
        HashMap<String , Object> userInfoCustomData = new HashMap<String , Object>();
        userInfoCustomData.put("KEY" , "VALUE");
        MMIntegrationWrapper.reportSubscriberInfo("SUBSCRIBER_ID","SUBSCRIBER_TYPE","SUBSCRIBER_TAG","PROFILE_ID",userInfoCustomData);
        ...
    }
    @Override
    public void onTerminate() {
        super.onTerminate();
        MMIntegrationWrapper.release(true);
    }
}
```

{% hint style="info" %}
**Note:**\
you can rename `MyApplication.java` according to your application
{% endhint %}

Now you need to mention in your `MyApplication.java`  AndroidManifest.xml

```java
 <application
        ...
           android:name=".MyApplication"
        ...
   </application>
```

## Step 3: Custom Data & Referral Data

```java
//Report Referral data
HashMap<String,Object> referralCustomData = new HashMap<String,Object>()
referralCustomData.put("REFERAl_KEY", "R_VALUE");
MMIntegrationWrapper.reportReferralInfo("REFERRAL_ID",referralCustomData);

// Report custom data
HashMap<String,Object> customData = new HashMap<String,Object>()
customData.put("KEY","VALUE")
MMIntegrationWrapper.reportCustomData("EVENT_NAME",customData)
```

## Step 4 : User Actions

* #### Screen View

```java
HashMap<String,Object> screenData = new HashMap<String,Object>()
screenData.put("KEY","VALUE")
MMIntegrationWrapper.reportScreenView("EVENT_NAME",screenData)
```

* #### Event

```java
HashMap<String,Object> eventData = new HashMap<String,Object>()
eventData.put("KEY","VALUE")
MMIntegrationWrapper.reportEvent("EVENT_NAME",eventData)
```

* #### App State

```java
MMIntegrationWrapper.reportAppState("APP_STATE")
```

* #### App Error

<pre class="language-java"><code class="lang-java">HashMap&#x3C;String,Object> errorData = new HashMap&#x3C;String,Object>()
errorData.put("KEY","VALUE")
<strong>MMIntegrationWrapper.reportAppError("APP_ERROR" , errorData)
</strong></code></pre>

* #### Video State

```java
HashMap<String,Object> videoData = new HashMap<String,Object>()
videoData.put("KEY","VALUE")
MMIntegrationWrapper.reportVideoState("VIDEO_STATE" , videoData)
```

* #### Interruption

```java
HashMap<String,Object> interruptionData = new HashMap<String,Object>()
interruptionData.put("KEY","VALUE")
MMIntegrationWrapper.reportInterruption("INTERRUTION_TYPE" , interruptionData)
```

* #### Purchase

```java
HashMap<String,Object> purchaseData = new HashMap<String,Object>()
purchaseData.put("KEY","VALUE")
MMIntegrationWrapper.reportPurchase("PURCHASE_TYPE" , purchaseData)
```

* #### Subscription

<pre class="language-java"><code class="lang-java"><strong>HashMap&#x3C;String,Object> subscriptionData = new HashMap&#x3C;String,Object>()
</strong>subscriptionData.put("KEY","VALUE")
MMIntegrationWrapper.reportSubcription("SUBSCRIPTION_TYPE" , subscriptionData)
</code></pre>

## Step 4: Report Ended State to the SDK

```java
 MMIntegrationWrapper.release(true);
```

| Variable         | Description                                                                                                                                                                          |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| CUSTOMER\_ID     | String containing your MediaMelon-assigned Customer ID.                                                                                                                              |
| SUBSCRIBER\_ID   | String containing your subscriber’s ID. If you do not use subscriber IDs, enter null                                                                                                 |
| SUBSCRIBER\_TYPE | String containing the subscriber type (e.g. “Free”, “Paid”). If you do not use subscriber types, enter null                                                                          |
| SUBSCRIBER\_TAG  | String containing an additional subscriber-specific information. This is sent in clear (not hashed) to SmartSight and it is advised to not send sensitive information in this field. |
| PROFILE\_ID      | ...                                                                                                                                                                                  |
| REFERRAL\_ID     | A unique referral id                                                                                                                                                                 |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mediamelon.com/mediamelon/smartsight-player-sdk-integration/android/app-analytics-sdk.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
