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;
}
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;
}
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));
}
}
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());
}
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();
}
Aggregations