Skip to content

Commit

Permalink
Merge pull request #150 from adjust/trademob-feature/trademob_plugin
Browse files Browse the repository at this point in the history
Trademob feature/trademob plugin
  • Loading branch information
nonelse committed Nov 16, 2015
2 parents 963a46f + d9e929f commit ed109c8
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Adjust/adjust/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ android {
minSdkVersion 9
targetSdkVersion 21
versionCode 1
versionName "4.1.3"
versionName "4.1.4"
}
}

Expand Down
2 changes: 1 addition & 1 deletion Adjust/adjust/src/main/java/com/adjust/sdk/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public interface Constants {
String BASE_URL = "https://app.adjust.com";
String SCHEME = "https";
String AUTHORITY = "app.adjust.com";
String CLIENT_SDK = "android4.1.3";
String CLIENT_SDK = "android4.1.4";
String LOGTAG = "Adjust";
String REFTAG = "reftag";

Expand Down
2 changes: 1 addition & 1 deletion Adjust/example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ dependencies {
// running mvn package
//compile fileTree(dir: '../target', include: ['*.jar'])
// using maven repository
//compile 'com.adjust.sdk:adjust-android:4.1.3'
//compile 'com.adjust.sdk:adjust-android:4.1.4'
}
129 changes: 129 additions & 0 deletions Adjust/plugin/AdjustTrademob.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.adjust.sdk.plugin;


import com.adjust.sdk.AdjustEvent;
import com.adjust.sdk.AdjustFactory;
import com.adjust.sdk.ILogger;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;


public class AdjustTrademob {

private static int MAX_LISTING_ITEMS_COUNT = 5;

private static ILogger logger = AdjustFactory.getLogger();

public static void injectViewItemIntoEvent(AdjustEvent event, String itemId, Map<String, String> metadata) {
event.addPartnerParameter("tm_item", itemId);
String jsonMetadata = stringifyMetadata(metadata);
event.addPartnerParameter("tm_md", jsonMetadata);
}

public static void injectViewListingIntoEvent(AdjustEvent event, List<String> itemIds, Map<String, String> metadata) {
String jsonItems = stringifyItemIds(itemIds);
event.addPartnerParameter("tm_item", jsonItems);
String jsonMetadata = stringifyMetadata(metadata);
event.addPartnerParameter("tm_md", jsonMetadata);
}

public static void injectAddToBasketIntoEvent(AdjustEvent event, List<TrademobItem> items, Map<String, String> metadata) {
String jsonMetadata = stringifyMetadata(metadata);
event.addPartnerParameter("tm_md", jsonMetadata);
String jsonItems = stringifyItems(items);
event.addPartnerParameter("tm_item", jsonItems);
}

public static void injectCheckoutIntoEvent(AdjustEvent event, List<TrademobItem> items, Map<String, String> metadata) {
String jsonMetadata = stringifyMetadata(metadata);
event.addPartnerParameter("tm_md", jsonMetadata);
String jsonItems = stringifyItems(items);
event.addPartnerParameter("tm_item", jsonItems);
}

private static String stringifyItemIds(List<String> itemIds) {
if (itemIds == null) {
logger.warn("TM View Listing item ids list is null. Empty ids array will be sent.");
itemIds = new ArrayList<String>();
}
StringBuffer tmViewList = new StringBuffer("[");
int itemsSize = itemIds.size();
int i = 0;

while (i < itemsSize) {
String itemId = itemIds.get(i);
String itemString = String.format(Locale.US, "\"%s\"", itemId);
tmViewList.append(itemString);

i++;

if (i == itemsSize || i >= MAX_LISTING_ITEMS_COUNT) {
break;
}

tmViewList.append(",");
}

tmViewList.append("]");

return tmViewList.toString();
}

private static String stringifyItems(List<TrademobItem> items) {
if (items == null) {
logger.warn("TM View Listing item ids list is empty. Empty items will be sent.");
items = new ArrayList<TrademobItem>();
}

StringBuffer itemsStrBuffer = new StringBuffer("[");
int itemsSize = items.size();

for (int i = 0; i < itemsSize; ) {
TrademobItem item = items.get(i);
String itemString = String.format(Locale.US, "{\"id\":\"%s\",\"price\":%f,\"quantity\":%d}",
item.itemId,
item.price,
item.quantity);
itemsStrBuffer.append(itemString);

i++;

if (i == itemsSize || i >= MAX_LISTING_ITEMS_COUNT) {
break;
}

itemsStrBuffer.append(",");
}

itemsStrBuffer.append("]");

return itemsStrBuffer.toString();
}

private static String stringifyMetadata(Map<String, String> metadata) {

if(null == metadata) {
return "{}";
}
String res = "{";

Iterator<Map.Entry<String, String>> iterator = metadata.entrySet().iterator();

while(iterator.hasNext()) {
Map.Entry<String, String> entry = iterator.next();
String key = "\"".concat(entry.getKey()).concat("\"");
String value = "\"".concat(entry.getValue()).concat("\"");
res = res.concat(key).concat(":").concat(value);

if (iterator.hasNext()) {
res = res.concat(",");
}
}

return res.concat("}");
}
}
13 changes: 13 additions & 0 deletions Adjust/plugin/TrademobItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.adjust.sdk.plugin;

public class TrademobItem {
float price;
int quantity;
String itemId;

public TrademobItem(String itemId, int quantity, float price) {
this.price = price;
this.quantity = quantity;
this.itemId = itemId;
}
}
2 changes: 1 addition & 1 deletion Adjust/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>adjust-android</artifactId>
<groupId>com.adjust.sdk</groupId>
<version>4.1.3</version>
<version>4.1.4</version>
<packaging>jar</packaging>
<name>Adjust Android SDK</name>
<url>https://github.com/adjust/android_sdk</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public TestActivityPackage(ActivityPackage activityPackage) {
// default values
appToken = "123456789012";
environment = "sandbox";
clientSdk = "android4.1.3";
clientSdk = "android4.1.4";
suffix = "";
attribution = new AdjustAttribution();
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ compile project(":adjust")
If you are using Maven, add this line instead:

```
compile 'com.adjust.sdk:adjust-android:4.1.3'
compile 'com.adjust.sdk:adjust-android:4.1.4'
```

### 4. Add Google Play Services
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.1.3
4.1.4
2 changes: 1 addition & 1 deletion doc/migrate.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Migrate your adjust SDK for Android to 4.1.3 from 3.6.2
## Migrate your adjust SDK for Android to 4.1.4 from 3.6.2

### The Application class

Expand Down
92 changes: 92 additions & 0 deletions doc/trademob_plugin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
## Trademob plugin

Integrate adjust with Trademob events by following these steps:

1. Locate the `plugin` folder inside the downloaded archive from our
[releases page](https://github.com/adjust/android_sdk/releases).

2. Open the `adjust` module in Android Studio and locate the
`plugin` package folder in `adjust/java/com/adjust/sdk`.

3. Drag the `AdjustTrademob.java` and `TrademobItem.java` files from the
downloaded `plugin` folder into the `plugin` folder in the `adjust` project.

For questions regarding this plugin, please reach out to `[email protected]`

You can now use Trademob event in the following ways:

### View Listing

```java
import com.adjust.sdk.plugin.AdjustTrademob;

AdjustEvent event = new AdjustEvent("{viewListingEventToken}");

List<String> items = Arrays.asList("itemId1", "itemId2", "itemId3");

Map<String, String> metadata = new HashMap<>();
metadata.put("info1", "value1");
metadata.put("info2", "value2");

AdjustTrademob.injectViewListingIntoEvent(event, items, metadata);

Adjust.trackEvent(event);
```

### View Item

```java
import com.adjust.sdk.plugin.AdjustTrademob;

AdjustEvent event = new AdjustEvent("{viewItemEventToken}");

Map<String, String> metadata = new HashMap<>();
metadata.put("info1", "value1");
metadata.put("info2", "value2");

AdjustTrademob.injectViewItemIntoEvent(event, "itemId1", metadata);

Adjust.trackEvent(event);
```

### Add to Basket

```java
import com.adjust.sdk.plugin.AdjustTrademob;
import com.adjust.sdk.plugin.TrademobItem;

AdjustEvent event = new AdjustEvent("{basketEventToken}");

TrademobItem itemId1 = new TrademobItem("itemId1", 2, 54f);
TrademobItem itemId2 = new TrademobItem("itemId2", 1, 3f);
TrademobItem itemId3 = new TrademobItem("itemId3", 4, 25f);

List<TrademobItem> items = Arrays.asList(itemId1, itemId2, itemId3);

AdjustTrademob.injectAddToBasketIntoEvent(event, items, null);

Adjust.trackEvent(event);
```

### Checkout

```java
import com.adjust.sdk.plugin.AdjustTrademob;
import com.adjust.sdk.plugin.TrademobItem;

AdjustEvent event = new AdjustEvent("{checkoutEventToken}");

TrademobItem itemId1 = new TrademobItem("itemId1", 2, 54f);
TrademobItem itemId2 = new TrademobItem("itemId2", 1, 3f);
TrademobItem itemId3 = new TrademobItem("itemId3", 4, 25f);

List<TrademobItem> items = Arrays.asList(itemId1, itemId2, itemId3);

Map<String, String> metadata = new HashMap<>();
metadata.put("info1", "value1");
metadata.put("info2", "value2");

AdjustTrademob.injectCheckoutIntoEvent(event, items, metadata);

Adjust.trackEvent(event);
```

0 comments on commit ed109c8

Please sign in to comment.