Search in sources :

Example 1 with AWSPinpointUserProfile

use of com.amplifyframework.analytics.pinpoint.models.AWSPinpointUserProfile in project amplify-android by aws-amplify.

the class AnalyticsPinpointInstrumentedTest method testIdentifyUserWithUserAtrributes.

/**
 * {@link AWSPinpointUserProfile} extends {@link UserProfile} to include
 * {@link AWSPinpointUserProfile#userAttributes} which is specific to Pinpoint. This test is very
 * similar to testIdentifyUserWithDefaultProfile, but it adds user attributes in additional
 * to the endpoint attributes.
 */
@Test
public void testIdentifyUserWithUserAtrributes() {
    UserProfile.Location location = getTestLocation();
    AnalyticsProperties properties = getEndpointProperties();
    AnalyticsProperties userAttributes = getUserAttributes();
    AWSPinpointUserProfile pinpointUserProfile = AWSPinpointUserProfile.builder().name("test-user").email("user@test.com").plan("test-plan").location(location).customProperties(properties).userAttributes(userAttributes).build();
    Amplify.Analytics.identifyUser("userId", pinpointUserProfile);
    EndpointProfile endpointProfile = targetingClient.currentEndpoint();
    assertCommonEndpointProfileProperties(endpointProfile);
    assertEquals("User attribute value", endpointProfile.getUser().getUserAttributes().get("SomeUserAttribute").get(0));
}
Also used : AnalyticsProperties(com.amplifyframework.analytics.AnalyticsProperties) EndpointProfile(com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile) AWSPinpointUserProfile(com.amplifyframework.analytics.pinpoint.models.AWSPinpointUserProfile) UserProfile(com.amplifyframework.analytics.UserProfile) AWSPinpointUserProfile(com.amplifyframework.analytics.pinpoint.models.AWSPinpointUserProfile) Test(org.junit.Test)

Example 2 with AWSPinpointUserProfile

use of com.amplifyframework.analytics.pinpoint.models.AWSPinpointUserProfile in project amplify-android by aws-amplify.

the class AWSPinpointAnalyticsPlugin method identifyUser.

@Override
public void identifyUser(@NonNull String userId, @Nullable UserProfile userProfile) {
    Objects.requireNonNull(userId);
    EndpointProfile endpointProfile = targetingClient.currentEndpoint();
    // Assign userId to the endpoint.
    EndpointProfileUser user = new EndpointProfileUser();
    user.setUserId(userId);
    if (userProfile instanceof AWSPinpointUserProfile) {
        AWSPinpointUserProfile pinpointUserProfile = (AWSPinpointUserProfile) userProfile;
        if (pinpointUserProfile.getUserAttributes() != null) {
            addUserAttributes(user, pinpointUserProfile.getUserAttributes());
        }
    }
    endpointProfile.setUser(user);
    // Add user-specific data to the endpoint
    if (userProfile != null) {
        addUserProfileToEndpoint(endpointProfile, userProfile);
    }
    // update endpoint
    targetingClient.updateEndpointProfile(endpointProfile);
}
Also used : EndpointProfileUser(com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfileUser) EndpointProfile(com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile) AWSPinpointUserProfile(com.amplifyframework.analytics.pinpoint.models.AWSPinpointUserProfile)

Aggregations

EndpointProfile (com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile)2 AWSPinpointUserProfile (com.amplifyframework.analytics.pinpoint.models.AWSPinpointUserProfile)2 EndpointProfileUser (com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfileUser)1 AnalyticsProperties (com.amplifyframework.analytics.AnalyticsProperties)1 UserProfile (com.amplifyframework.analytics.UserProfile)1 Test (org.junit.Test)1