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

feat(firebase_analytics, ios): add onDeviceConversionMeasurement #11795

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

lucasuracosta
Copy link

Description

This PR adds the onDeviceConversionMeasurement function for ios which is needed for an increased volume and precision of conversion tracking.

I followed as example @mikehardy's implementation of the feature in React Native and @Lyokone's implementation of Pigeon.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

@mikehardy
Copy link
Contributor

Just dropping by for a moment since I saw my tag here 👋 - wanted to note that there is a phone API as well with firebase-ios-sdk 10.13.0+

invertase/react-native-firebase#7358

Same basic pattern, might make sense to get them both in at once

Copy link
Contributor

@Lyokone Lyokone left a comment

Choose a reason for hiding this comment

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

Some comments, but looks really good, thanks for this :)

Comment on lines +172 to +182
- (void)setAutomaticDataCollectionEnabledAppName:(nonnull NSString *)appName
enabled:(nonnull NSNumber *)enabled
completion:
(nonnull void (^)(FlutterError *_Nullable))completion {
FIRApp *firebaseApp = [FLTFirebasePlugin firebaseAppNamed:appName];
if (firebaseApp) {
[firebaseApp setDataCollectionDefaultEnabled:[enabled boolValue]];
}

completion(nil);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not seeing where this method is being called. You probably need to add something in the handleMethodCall

Copy link
Author

Choose a reason for hiding this comment

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

@Lyokone I thought the same at first glance, but actually it's being called inside the FirebaseAnalyticsHostApiSetup

firebase_analytics_messages.g.m

void FirebaseAnalyticsHostApiSetup(id<FlutterBinaryMessenger> binaryMessenger,
                                   NSObject<FirebaseAnalyticsHostApi> *api) {
  {
    FlutterBasicMessageChannel *channel = [[FlutterBasicMessageChannel alloc]
           initWithName:
               @"dev.flutter.pigeon.firebase_analytics_platform_interface.FirebaseAnalyticsHostApi."
               @"initiateOnDeviceConversionMeasurementWithEmailAddress"
        binaryMessenger:binaryMessenger
                  codec:FirebaseAnalyticsHostApiGetCodec()];
    if (api) {
      NSCAssert([api respondsToSelector:@selector
                     (initiateOnDeviceConversionMeasurementWithEmailAddressEmailAddress:
                                                                             completion:)],
                @"FirebaseAnalyticsHostApi api (%@) doesn't respond to "
                @"@selector(initiateOnDeviceConversionMeasurementWithEmailAddressEmailAddress:"
                @"completion:)",
                api);
      [channel setMessageHandler:^(id _Nullable message, FlutterReply callback) {
        printf("Inside newMessageHandler");
        NSArray *args = message;
        NSString *arg_emailAddress = GetNullableObjectAtIndex(args, 0);
        [api initiateOnDeviceConversionMeasurementWithEmailAddressEmailAddress:arg_emailAddress
                                                                    completion:^(
                                                                        FlutterError
                                                                            *_Nullable error) {
                                                                      callback(
                                                                          wrapResult(nil, error));
                                                                    }];
      }];
    } else {
      [channel setMessageHandler:nil];
    }
  }
}

It receives the binary messenger and sets a parallel channel, which then calls to the appropriate function. If you run the example, you'll see that the function is properly executed and (if you add the print I wrote in this example) the print too.

In short, there's no need to call it in handleMethodCall, Pigeon already does it.

The ideal would be to have all the functions of firebase_analytics migrated into pigeon, then all of them would be called in the same place. But I think this would be overkill for this scenario and it would transform this non-breaking PR into a breaking one.

@lucasuracosta
Copy link
Author

Hi, thanks for the feedback! I'll work on your comments this week 😄

@lucasuracosta
Copy link
Author

@Lyokone All your recommendations were implemented and I left a comment on your concern about its functioning.

All things considered we should be good to go, right?

P.S: I'll eventually add the equivalent of this implementation for phone numbers in a separate PR but I can't promise it will be soon, so I would rather go only with this one for now.

@mikehardy
Copy link
Contributor

P.S: I'll eventually add the equivalent of this implementation for phone numbers in a separate PR but I can't promise it will be soon, so I would rather go only with this one for now.

Sure - did not mean to imply any sort of pressure, just wanted to mention it since whenever this PR makes it through review, using whatever code looks good, the other API should be doing exactly the same thing, so it's potentially a really really quick hit that re-uses all the kind-of-ephemeral wisdom built up on how to do the PR and review it etc.

But no one has endless time of course, I certainly feel that! Cheers

@lucasuracosta
Copy link
Author

Ohhh I get what you meant now, thanks!!!

@lucasuracosta
Copy link
Author

@Lyokone Just checking back on this one, is there anything missing for it to be ready? 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants