Search in sources :

Example 16 with AnalyticsEvent

use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent in project aws-sdk-android by aws-amplify.

the class AmazonMonetizationEventBuilderTest method verifyMonetizationEvent.

private static void verifyMonetizationEvent(AmazonMonetizationEventBuilder builder, boolean successfulBuild, String productId, String formattedPrice, Double quantity, String currency, Double itemPrice) {
    if (productId != null) {
        builder.setProductId(productId);
    }
    if (formattedPrice != null) {
        builder.setFormattedItemPrice(formattedPrice);
    }
    if (quantity != null) {
        builder.setQuantity(quantity);
    }
    if (currency != null) {
        builder.setCurrency(currency);
    }
    if (itemPrice != null) {
        builder.setItemPrice(itemPrice);
    }
    AnalyticsEvent purchaseEvent = builder.build();
    if (successfulBuild) {
        assertThat(purchaseEvent, is(not(nullValue())));
        assertThat(purchaseEvent.getEventType(), is(MonetizationEventBuilder.PURCHASE_EVENT_NAME));
        Map<String, String> attributes = purchaseEvent.getAllAttributes();
        assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_PRODUCT_ID_ATTR), is(productId));
        assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_TRANSACTION_ID_ATTR), is(nullValue()));
        assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_STORE_ATTR), is(MonetizationEventBuilder.AMAZON_STORE));
        Map<String, Double> metrics = purchaseEvent.getAllMetrics();
        assertThat(metrics.get(MonetizationEventBuilder.PURCHASE_EVENT_QUANTITY_METRIC).doubleValue(), is(quantity));
        if (currency == null || itemPrice == null) {
            assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_PRICE_FORMATTED_ATTR), is(formattedPrice));
        }
    } else {
        assertThat(purchaseEvent, is(nullValue()));
    }
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent)

Example 17 with AnalyticsEvent

use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent in project aws-sdk-android by aws-amplify.

the class CustomMonetizationEventBuilderTest method verifyMonetizationEvent.

private static void verifyMonetizationEvent(CustomMonetizationEventBuilder builder, boolean successfulBuild, String store, String productId, Double quantity, String formattedPrice, Double itemPrice, String currency, String transactionId) {
    if (store != null) {
        builder.setStore(store);
    }
    if (productId != null) {
        builder.setProductId(productId);
    }
    if (quantity != null) {
        builder.setQuantity(quantity);
    }
    if (formattedPrice != null) {
        builder.setFormattedItemPrice(formattedPrice);
    }
    if (itemPrice != null) {
        builder.setItemPrice(itemPrice);
    }
    if (currency != null) {
        builder.setCurrency(currency);
    }
    if (transactionId != null) {
        builder.setTransactionId(transactionId);
    }
    AnalyticsEvent purchaseEvent = builder.build();
    if (successfulBuild) {
        assertThat(purchaseEvent, is(not(nullValue())));
        assertThat(purchaseEvent.getEventType(), is(MonetizationEventBuilder.PURCHASE_EVENT_NAME));
        Map<String, String> attributes = purchaseEvent.getAllAttributes();
        assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_STORE_ATTR), is(store));
        assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_PRODUCT_ID_ATTR), is(productId));
        if (currency != null) {
            assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_CURRENCY_ATTR), is(currency));
        } else {
            assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_CURRENCY_ATTR), is(nullValue()));
        }
        if (formattedPrice != null) {
            assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_PRICE_FORMATTED_ATTR), is(formattedPrice));
        } else {
            assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_PRICE_FORMATTED_ATTR), is(nullValue()));
        }
        if (transactionId != null) {
            assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_TRANSACTION_ID_ATTR), is(transactionId));
        } else {
            assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_TRANSACTION_ID_ATTR), is(nullValue()));
        }
        Map<String, Double> metrics = purchaseEvent.getAllMetrics();
        assertThat(metrics.get(MonetizationEventBuilder.PURCHASE_EVENT_QUANTITY_METRIC).doubleValue(), is(quantity));
        if (itemPrice != null) {
            assertThat(metrics.get(MonetizationEventBuilder.PURCHASE_EVENT_ITEM_PRICE_METRIC).doubleValue(), is(itemPrice));
        } else {
            assertThat(metrics.get(MonetizationEventBuilder.PURCHASE_EVENT_ITEM_PRICE_METRIC), is(nullValue()));
        }
    } else {
        assertThat(purchaseEvent, is(nullValue()));
    }
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent)

Example 18 with AnalyticsEvent

use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent in project aws-sdk-android by aws-amplify.

the class GooglePlayMonetizationEventBuilderTest method verifyMonetizationEvent.

private static void verifyMonetizationEvent(GooglePlayMonetizationEventBuilder builder, boolean successfulBuild, String productId, String currency, Double quantity, String transactionId, Double itemPrice) {
    if (productId != null) {
        builder.setProductId(productId);
    }
    if (currency != null) {
        builder.setCurrency(currency);
    }
    if (quantity != null) {
        builder.setQuantity(quantity);
    }
    if (itemPrice != null) {
        builder.setItemPrice(itemPrice);
    }
    if (transactionId != null) {
        builder.setTransactionId(transactionId);
    }
    AnalyticsEvent purchaseEvent = builder.build();
    if (successfulBuild) {
        assertThat(purchaseEvent, is(not(nullValue())));
        assertThat(purchaseEvent.getEventType(), is(MonetizationEventBuilder.PURCHASE_EVENT_NAME));
        Map<String, String> attributes = purchaseEvent.getAllAttributes();
        assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_PRODUCT_ID_ATTR), is(productId));
        assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_TRANSACTION_ID_ATTR), is(transactionId));
        assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_STORE_ATTR), is(MonetizationEventBuilder.GOOGLE_PLAY_STORE));
        assertThat(attributes.get(MonetizationEventBuilder.PURCHASE_EVENT_CURRENCY_ATTR), is(not(nullValue())));
        Map<String, Double> metrics = purchaseEvent.getAllMetrics();
        assertThat(metrics.get(MonetizationEventBuilder.PURCHASE_EVENT_QUANTITY_METRIC).doubleValue(), is(quantity));
        assertThat(metrics.get(MonetizationEventBuilder.PURCHASE_EVENT_ITEM_PRICE_METRIC), is(not(nullValue())));
    } else {
        assertThat(purchaseEvent, is(nullValue()));
    }
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent)

Example 19 with AnalyticsEvent

use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent in project aws-sdk-android by aws-amplify.

the class GooglePlayMonetizationEventBuilderTest method setup.

@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    when(mockConfiguration.optString("versionKey", "ver")).thenReturn("ver");
    when(mockConfiguration.optBoolean("isAnalyticsEnabled", true)).thenReturn(true);
    PinpointContext mockContext = new AnalyticsContextBuilder().withConfiguration(mockConfiguration).withContext(RuntimeEnvironment.application.getApplicationContext()).build();
    target = new AnalyticsClient(mockContext);
    AnalyticsEvent testEvent = target.createEvent(MonetizationEventBuilder.PURCHASE_EVENT_NAME);
    when(mockEventClient.createEvent(MonetizationEventBuilder.PURCHASE_EVENT_NAME)).thenReturn(testEvent);
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) PinpointContext(com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext) AnalyticsClient(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient) AnalyticsContextBuilder(com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder) Before(org.junit.Before)

Example 20 with AnalyticsEvent

use of com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent in project aws-sdk-android by aws-amplify.

the class MonetizationEventBuilder method build.

/**
 * Builds a monetization event.
 *
 * @return A monetization event that can be recorded. If the builder is in
 * an invalid state, this method returns null.
 */
public AnalyticsEvent build() {
    AnalyticsEvent purchaseEvent = null;
    if (isValid() && doBaseValidation()) {
        purchaseEvent = analyticsClient.createEvent(PURCHASE_EVENT_NAME);
        purchaseEvent.addAttribute(PURCHASE_EVENT_PRODUCT_ID_ATTR, productId);
        purchaseEvent.addAttribute(PURCHASE_EVENT_STORE_ATTR, store);
        purchaseEvent.addMetric(PURCHASE_EVENT_QUANTITY_METRIC, quantity);
        if (formattedItemPrice != null) {
            purchaseEvent.addAttribute(PURCHASE_EVENT_PRICE_FORMATTED_ATTR, formattedItemPrice);
        }
        if (itemPrice != null) {
            purchaseEvent.addMetric(PURCHASE_EVENT_ITEM_PRICE_METRIC, itemPrice);
        }
        if (transactionId != null) {
            purchaseEvent.addAttribute(PURCHASE_EVENT_TRANSACTION_ID_ATTR, transactionId);
        }
        if (currency != null) {
            purchaseEvent.addAttribute(PURCHASE_EVENT_CURRENCY_ATTR, currency);
        }
    }
    return purchaseEvent;
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent)

Aggregations

AnalyticsEvent (com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent)41 Test (org.junit.Test)27 Map (java.util.Map)16 AnalyticsClient (com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient)7 HashMap (java.util.HashMap)6 AnalyticsContextBuilder (com.amazonaws.mobileconnectors.pinpoint.analytics.utils.AnalyticsContextBuilder)5 PinpointContext (com.amazonaws.mobileconnectors.pinpoint.internal.core.PinpointContext)5 Before (org.junit.Before)5 Uri (android.net.Uri)4 Cursor (android.database.Cursor)3 Event (com.amazonaws.services.pinpoint.model.Event)2 JSONObject (org.json.JSONObject)2 Service (android.app.Service)1 Bundle (android.os.Bundle)1 MockAppDetails (com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockAppDetails)1 EventsBatch (com.amazonaws.services.pinpoint.model.EventsBatch)1 PublicEndpoint (com.amazonaws.services.pinpoint.model.PublicEndpoint)1 PutEventsRequest (com.amazonaws.services.pinpoint.model.PutEventsRequest)1 Locale (java.util.Locale)1 JSONException (org.json.JSONException)1