-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from adjust/trademob-feature/trademob_plugin
Trademob feature/trademob plugin
- Loading branch information
Showing
11 changed files
with
242 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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("}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4.1.3 | ||
4.1.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
``` |