Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Card FPTI Analytics Events #850

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Card/src/main/java/com/braintreepayments/api/CardAnalytics.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.braintreepayments.api

internal enum class CardAnalytics(@JvmField val event: String) {
internal object CardAnalytics {

CARD_TOKENIZE_STARTED("card:tokenize:started"),
CARD_TOKENIZE_FAILED("card:tokenize:failed"),
CARD_TOKENIZE_SUCCEEDED("card:tokenize:succeeded")
const val CARD_TOKENIZE_STARTED = "card:tokenize:started"
const val CARD_TOKENIZE_FAILED = "card:tokenize:failed"
const val CARD_TOKENIZE_SUCCEEDED = "card:tokenize:succeeded"
}
26 changes: 16 additions & 10 deletions Card/src/main/java/com/braintreepayments/api/CardClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ public CardClient(@NonNull Context context, @NonNull String authorization) {
* @param callback {@link CardTokenizeCallback}
*/
public void tokenize(@NonNull final Card card, @NonNull final CardTokenizeCallback callback) {
braintreeClient.sendAnalyticsEvent(CardAnalytics.CARD_TOKENIZE_STARTED);
braintreeClient.getConfiguration((configuration, error) -> {
if (error != null) {
callback.onCardResult(new CardResult.Failure(error));
callbackFailure(callback, new CardResult.Failure(error));
return;
}

Expand All @@ -80,7 +81,7 @@ public void tokenize(@NonNull final Card card, @NonNull final CardTokenizeCallba
(tokenizationResponse, exception) -> handleTokenizeResponse(
tokenizationResponse, exception, callback));
} catch (BraintreeException | JSONException e) {
callback.onCardResult(new CardResult.Failure(e));
callbackFailure(callback, new CardResult.Failure(e));
}
} else {
apiClient.tokenizeREST(card,
Expand All @@ -95,17 +96,22 @@ private void handleTokenizeResponse(JSONObject tokenizationResponse, Exception e
if (tokenizationResponse != null) {
try {
CardNonce cardNonce = CardNonce.fromJSON(tokenizationResponse);

callback.onCardResult(new CardResult.Success(cardNonce));
braintreeClient.sendAnalyticsEvent("card.nonce-received");

callbackSuccess(callback, new CardResult.Success(cardNonce));
} catch (JSONException e) {
callback.onCardResult(new CardResult.Failure(e));
braintreeClient.sendAnalyticsEvent("card.nonce-failed");
callbackFailure(callback, new CardResult.Failure(e));
}
} else if (exception != null) {
callback.onCardResult(new CardResult.Failure(exception));
braintreeClient.sendAnalyticsEvent("card.nonce-failed");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these existing events already being sent to FPTI? Just want to make sure that this change doesn't break any existing reports.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know, there aren't any existing reports that are based on the old events, and the new dashboards will be based on these new planned events - but @scannillo correct me if I'm wrong.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a great question. So on this V5 branch, we already merged in a change that sends our analytics directly to FPTI versus sending to the old BT analytics service (Arachne).

The old events weren't being used in any dashboard, but these new events now mirror the ones on BT iOS V6, and will be able to be used in our new conversion dashboard that we share b/w BT & PPCP mobile.

With Android V5, we're doing this analytics cleanup to keep things consistent across platform & product

callbackFailure(callback, new CardResult.Failure(exception));
}
}

private void callbackFailure(CardTokenizeCallback callback, CardResult cardResult) {
braintreeClient.sendAnalyticsEvent(CardAnalytics.CARD_TOKENIZE_FAILED);
callback.onCardResult(cardResult);
}

private void callbackSuccess(CardTokenizeCallback callback, CardResult cardResult) {
braintreeClient.sendAnalyticsEvent(CardAnalytics.CARD_TOKENIZE_SUCCEEDED);
callback.onCardResult(cardResult);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class CardAnalyticsUnitTest {

@Test
fun testAnalyticsEvents_sendsExpectedEventNames() {
assertEquals("card:tokenize:started", CardAnalytics.CARD_TOKENIZE_STARTED.event)
assertEquals("card:tokenize:failed", CardAnalytics.CARD_TOKENIZE_FAILED.event)
assertEquals("card:tokenize:succeeded", CardAnalytics.CARD_TOKENIZE_SUCCEEDED.event)
assertEquals("card:tokenize:started", CardAnalytics.CARD_TOKENIZE_STARTED)
assertEquals("card:tokenize:failed", CardAnalytics.CARD_TOKENIZE_FAILED)
assertEquals("card:tokenize:succeeded", CardAnalytics.CARD_TOKENIZE_SUCCEEDED)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
@RunWith(RobolectricTestRunner.class)
public class CardClientUnitTest {

private Context context;
private Card card;
private CardTokenizeCallback cardTokenizeCallback;

Expand All @@ -35,7 +34,6 @@ public class CardClientUnitTest {

@Before
public void beforeEach() throws JSONException {
context = mock(Context.class);
card = new Card();
cardTokenizeCallback = mock(CardTokenizeCallback.class);

Expand All @@ -45,6 +43,18 @@ public void beforeEach() throws JSONException {
graphQLDisabledConfig = Configuration.fromJson(Fixtures.CONFIGURATION_WITHOUT_ACCESS_TOKEN);
}


sarahkoop marked this conversation as resolved.
Show resolved Hide resolved
@Test
public void tokenize_sendsTokenizeStartedAnalytics() {
BraintreeClient braintreeClient = new MockBraintreeClientBuilder().build();
apiClient = new MockApiClientBuilder().build();

CardClient sut = new CardClient(braintreeClient, apiClient);
sut.tokenize(card, cardTokenizeCallback);

verify(braintreeClient).sendAnalyticsEvent(CardAnalytics.CARD_TOKENIZE_STARTED);
}

@Test
public void tokenize_whenGraphQLEnabled_setsSessionIdOnCardBeforeTokenizing() {
BraintreeClient braintreeClient = new MockBraintreeClientBuilder()
Expand Down Expand Up @@ -121,7 +131,7 @@ public void tokenize_whenGraphQLEnabled_sendsAnalyticsEventOnSuccess() throws JS
CardClient sut = new CardClient(braintreeClient, apiClient);
sut.tokenize(card, cardTokenizeCallback);

verify(braintreeClient).sendAnalyticsEvent("card.nonce-received");
verify(braintreeClient).sendAnalyticsEvent(CardAnalytics.CARD_TOKENIZE_SUCCEEDED);
}

@Test
Expand All @@ -137,7 +147,7 @@ public void tokenize_whenGraphQLDisabled_sendsAnalyticsEventOnSuccess() throws J
CardClient sut = new CardClient(braintreeClient, apiClient);
sut.tokenize(card, cardTokenizeCallback);

verify(braintreeClient).sendAnalyticsEvent("card.nonce-received");
verify(braintreeClient).sendAnalyticsEvent(CardAnalytics.CARD_TOKENIZE_SUCCEEDED);
}

@Test
Expand Down Expand Up @@ -200,7 +210,7 @@ public void tokenize_whenGraphQLEnabled_sendsAnalyticsEventOnFailure() {
CardClient sut = new CardClient(braintreeClient, apiClient);
sut.tokenize(card, cardTokenizeCallback);

verify(braintreeClient).sendAnalyticsEvent("card.nonce-failed");
verify(braintreeClient).sendAnalyticsEvent(CardAnalytics.CARD_TOKENIZE_FAILED);
}

@Test
Expand All @@ -217,7 +227,7 @@ public void tokenize_whenGraphQLDisabled_sendsAnalyticsEventOnFailure() {
CardClient sut = new CardClient(braintreeClient, apiClient);
sut.tokenize(card, cardTokenizeCallback);

verify(braintreeClient).sendAnalyticsEvent("card.nonce-failed");
verify(braintreeClient).sendAnalyticsEvent(CardAnalytics.CARD_TOKENIZE_FAILED);
}

@Test
Expand Down
Loading