Search in sources :

Example 1 with AnalyticsEvent

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

the class EventRecorder method createRecordEventsRequest.

/**
 * @param events array of events
 * @param endpointProfile endpoint profile for the device endpoint
 *
 * @return the request to put event
 */
private PutEventsRequest createRecordEventsRequest(final JSONArray events, final EndpointProfile endpointProfile) {
    final PutEventsRequest putRequest = new PutEventsRequest().withApplicationId(endpointProfile.getApplicationId());
    final String endpointId = endpointProfile.getEndpointId();
    final Map<String, EventsBatch> eventsBatchMap = new HashMap<String, EventsBatch>();
    final EventsBatch eventsBatch = new EventsBatch();
    final PublicEndpoint endpoint = new PublicEndpoint();
    final Map<String, Event> eventsMap = new HashMap<String, Event>();
    // build endpoint payload
    buildEndpointPayload(endpointProfile, endpoint);
    for (int i = 0; i < events.length(); i++) {
        JSONObject eventJSON = null;
        AnalyticsEvent internalEvent = null;
        try {
            eventJSON = events.getJSONObject(i);
            internalEvent = AnalyticsEvent.translateToEvent(eventJSON);
        } catch (final JSONException jsonException) {
            // Do not log JSONException due to potentially sensitive information
            log.error("Stored event was invalid JSON.", jsonException);
            continue;
        }
        // build event payload
        final Event event = new Event();
        buildEventPayload(internalEvent, event);
        eventsMap.put(internalEvent.getEventId(), event);
    }
    // build request payload, could also build with only endpoint payload
    buildRequestPayload(putRequest, endpointId, eventsBatchMap, eventsBatch, endpoint, eventsMap);
    return putRequest;
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) Event(com.amazonaws.services.pinpoint.model.Event) JSONException(org.json.JSONException) PublicEndpoint(com.amazonaws.services.pinpoint.model.PublicEndpoint) PutEventsRequest(com.amazonaws.services.pinpoint.model.PutEventsRequest) EventsBatch(com.amazonaws.services.pinpoint.model.EventsBatch) PublicEndpoint(com.amazonaws.services.pinpoint.model.PublicEndpoint)

Example 2 with AnalyticsEvent

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

the class NotificationClientBase method handleNotificationOpen.

/* pkg */
NotificationClient.PushResult handleNotificationOpen(Map<String, String> eventSourceAttributes, final Bundle data) {
    // Add any campaign global attributes
    if (eventSourceAttributes != null) {
        EventSourceType eventSourceType = EventSourceType.getEventSourceType(data);
        // Stop Session
        if (this.pinpointContext.getSessionClient() != null) {
            this.pinpointContext.getSessionClient().stopSession();
        }
        this.pinpointContext.getAnalyticsClient().updateEventSourceGlobally(eventSourceAttributes);
        String eventType = eventSourceType.getEventTypeOpenend();
        final AnalyticsEvent pushEvent = this.pinpointContext.getAnalyticsClient().createEvent(eventType);
        this.pinpointContext.getAnalyticsClient().recordEvent(pushEvent);
        this.pinpointContext.getAnalyticsClient().submitEvents();
        final String url = data.getString(EVENT_SOURCE_URL_PUSH_KEY);
        if (url != null) {
            openURL(url, false);
            return NotificationClient.PushResult.NOTIFICATION_OPENED;
        }
        final String deepLink = data.getString(EVENT_SOURCE_DEEP_LINK_PUSH_KEY);
        if (deepLink != null) {
            openURL(deepLink, true);
            return NotificationClient.PushResult.NOTIFICATION_OPENED;
        }
        final String openApp = data.getString(EVENT_SOURCE_OPEN_APP_PUSH_KEY);
        if (openApp == null) {
            log.warn("No key/value present to determine action for pinpoint notification, default to open app.");
        }
        openApp();
    }
    return NotificationClient.PushResult.NOTIFICATION_OPENED;
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent)

Example 3 with AnalyticsEvent

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

the class EventLocaleTest method createEvent_verifyLocaleFormat.

@Test
public void createEvent_verifyLocaleFormat() throws JSONException {
    Map<String, Locale> locales = new HashMap<String, Locale>();
    locales.put("en_US", Locale.US);
    locales.put("en_CA", Locale.CANADA);
    locales.put("fr_CA", Locale.CANADA_FRENCH);
    locales.put("zh_CN", Locale.CHINA);
    locales.put("fr_FR", Locale.FRANCE);
    locales.put("de_DE", Locale.GERMANY);
    locales.put("it_IT", Locale.ITALY);
    locales.put("ja_JP", Locale.JAPAN);
    locales.put("ko_KR", Locale.KOREA);
    locales.put("zh_TW", Locale.TAIWAN);
    locales.put("en_GB", Locale.UK);
    locales.put("ar_SA", new Locale("ar", "SA"));
    locales.put("nl_NL", new Locale("nl", "NL"));
    locales.put("en_AU", new Locale("en", "AU"));
    locales.put("es_ES", new Locale("es", "ES"));
    locales.put("pt_BR", new Locale("pt", "BR"));
    locales.put("es_MX", new Locale("es", "MX"));
    for (String expectedLocaleName : locales.keySet()) {
        Locale expectedLocale = locales.get(expectedLocaleName);
        // create an event client
        AnalyticsClient target = new AnalyticsClient(createMockContext(expectedLocale));
        // create the event
        AnalyticsEvent event = target.createEvent("localeEvent");
        target.recordEvent(event);
        JSONObject jsonEvent = event.toJSONObject();
        assertThat(jsonEvent.getString("locale"), is(expectedLocaleName));
    }
}
Also used : Locale(java.util.Locale) AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) AnalyticsClient(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsClient) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with AnalyticsEvent

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

the class EventRecorderTest method testRecordEventPayload.

@Test
public void testRecordEventPayload() throws JSONException {
    final Event event = new Event();
    eventRecorder.buildEventPayload(analyticsEvent, event);
    final MockAppDetails mockAppDetails = new MockAppDetails();
    assertEquals(mockAppDetails.packageName(), event.getAppPackageName());
    assertEquals(mockAppDetails.getAppTitle(), event.getAppTitle());
    assertEquals(mockAppDetails.versionCode(), event.getAppVersionCode());
    assertEquals(EVENT_NAME, event.getEventType());
    assertEquals(SDK_NAME, event.getSdkName());
    assertEquals(SDK_VERSION, event.getClientSdkVersion());
    assertNotNull(event.getAttributes());
    assertTrue(event.getAttributes().equals(analyticsEvent.getAllAttributes()));
    assertEquals(event.getAttributes().get("key1"), "value1");
    assertEquals(event.getAttributes().get("key2"), "value2");
    assertNotNull(event.getMetrics());
    assertNotNull(event.getSession());
}
Also used : MockAppDetails(com.amazonaws.mobileconnectors.pinpoint.internal.core.system.MockAppDetails) AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) Event(com.amazonaws.services.pinpoint.model.Event) Test(org.junit.Test)

Example 5 with AnalyticsEvent

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

the class PinpointDBUtilTest method testQueryAll.

@Test
public void testQueryAll() {
    AnalyticsEvent analyticsEvent = AnalyticsEvent.newInstance(mockContext, SESSION_ID, SESSION_START, SESSION_END, SESSION_DURATION, TIME_STAMP, EVENT_NAME);
    Uri uri1 = dbUtil.saveEvent(analyticsEvent);
    Uri uri2 = dbUtil.saveEvent(analyticsEvent);
    int idInserted1 = Integer.parseInt(uri1.getLastPathSegment());
    int idInserted2 = Integer.parseInt(uri2.getLastPathSegment());
    assertNotEquals(idInserted1, 0);
    assertNotEquals(idInserted2, 0);
    Cursor c = dbUtil.queryAllEvents();
    assertNotNull(c);
    assertEquals(c.getCount(), 2);
    c.close();
}
Also used : AnalyticsEvent(com.amazonaws.mobileconnectors.pinpoint.analytics.AnalyticsEvent) Cursor(android.database.Cursor) Uri(android.net.Uri) Test(org.junit.Test)

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