Skip to content

Commit

Permalink
Merge pull request #149 from oddbit/version-0-14-0
Browse files Browse the repository at this point in the history
Version 0.14.0
  • Loading branch information
DennisAlund committed Oct 16, 2021
2 parents 14ae8ca + 263aa24 commit ec5c45e
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 182 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ android {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.facebook.android:facebook-core:11.+'
implementation 'com.facebook.android:facebook-android-sdk:12.+'
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ class FacebookAppEventsPlugin: FlutterPlugin, MethodCallHandler {
"getApplicationId" -> handleGetApplicationId(call, result)
"logEvent" -> handleLogEvent(call, result)
"logPushNotificationOpen" -> handlePushNotificationOpen(call, result)
"setUserData" -> handleSetUserData(call, result)
"setUserID" -> handleSetUserId(call, result)
"updateUserProperties" -> handleUpdateUserProperties(call, result)
"setAutoLogAppEventsEnabled" -> handleSetAutoLogAppEventsEnabled(call, result)
"setDataProcessingOptions" -> handleSetDataProcessingOptions(call, result)
"getAnonymousId" -> handleGetAnonymousId(call, result)
Expand Down Expand Up @@ -120,48 +118,6 @@ class FacebookAppEventsPlugin: FlutterPlugin, MethodCallHandler {
result.success(null)
}

private fun handleSetUserData(call: MethodCall, result: Result) {
val parameters = call.argument("parameters") as? Map<String, Object>
val parameterBundle = createBundleFromMap(parameters)

AppEventsLogger.setUserData(
parameterBundle?.getString("email"),
parameterBundle?.getString("firstName"),
parameterBundle?.getString("lastName"),
parameterBundle?.getString("phone"),
parameterBundle?.getString("dateOfBirth"),
parameterBundle?.getString("gender"),
parameterBundle?.getString("city"),
parameterBundle?.getString("state"),
parameterBundle?.getString("zip"),
parameterBundle?.getString("country")
)

result.success(null)
}

private fun handleUpdateUserProperties(call: MethodCall, result: Result) {
val applicationId = call.argument("applicationId") as? String
val parameters = call.argument("parameters") as? Map<String, Object>
val parameterBundle = createBundleFromMap(parameters) ?: Bundle()

val requestCallback = object : GraphRequest.Callback {
override fun onCompleted(response: GraphResponse) {
val data = response.getJSONObject()
result.success(data)
}
}

for (key in parameterBundle.keySet()) {
Log.d(logTag, "[updateUserProperties] " + key + ": " + parameterBundle.get(key))
}

if (applicationId == null) AppEventsLogger.updateUserProperties(parameterBundle, requestCallback)
else AppEventsLogger.updateUserProperties(parameterBundle, applicationId, requestCallback)

result.success(null)
}

private fun handleSetUserId(call: MethodCall, result: Result) {
val id = call.arguments as String
AppEventsLogger.setUserID(id)
Expand Down
22 changes: 10 additions & 12 deletions example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@

Demonstrates how to use the `facebook_app_events` plugin. Read the offical ["getting started" documentation](https://developers.facebook.com/docs/app-events/getting-started-app-events-android#custom-events) for full understanding.

## [Logging events](https://developers.facebook.com/docs/reference/androidsdk/current/facebook/com/facebook/appevents/appeventslogger.html/)
# Privacy Policy
Please note that this example project is configured to run against a Facebook app
that might collect your information if you run the example **as it is**.

```dart
import 'package:facebook_app_events/facebook_app_events.dart';
...
final facebookAppEvents = FacebookAppEvents();
facebookAppEvents.logEvent(
name: 'button_clicked',
parameters: {
'button_id': 'the_clickme_button',
},
);
```
Reconfigure the Facebook app integration if you do not wish to that the example
app reports any information to our test/debug app project.

By running this example project as it is you are approving any potential collection
of information that the plugin might provide.

We are not in using any of the collected information apart from troubleshooting
and for further development of the plugin.
9 changes: 9 additions & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ android {
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

signingConfigs {
debug {
storeFile file("../debug.keystore")
keyAlias "androiddebugkey"
storePassword "android"
keyPassword "android"
}
}

buildTypes {
release {
Expand Down
7 changes: 0 additions & 7 deletions example/android/app/src/debug/AndroidManifest.xml

This file was deleted.

4 changes: 0 additions & 4 deletions example/android/app/src/debug/res/values/strings.xml

This file was deleted.

20 changes: 17 additions & 3 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@
android:label="facebook_app_events_example"
android:icon="@mipmap/ic_launcher">

<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>

<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>

<activity
android:name=".MainActivity"
Expand Down
6 changes: 6 additions & 0 deletions example/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="facebook_app_id">391810292537784</string>
<string name="fb_login_protocol_scheme">fb391810292537784</string>
<string name="app_name">Flutter App Events Example</string>
</resources>
4 changes: 0 additions & 4 deletions example/android/app/src/release/res/values/strings.xml

This file was deleted.

Binary file added example/android/debug.keystore
Binary file not shown.
31 changes: 0 additions & 31 deletions ios/Classes/SwiftFacebookAppEventsPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,9 @@ public class SwiftFacebookAppEventsPlugin: NSObject, FlutterPlugin {
case "logPushNotificationOpen":
handlePushNotificationOpen(call, result: result)
break
case "setUserData":
handleSetUserData(call, result: result)
break
case "setUserID":
handleSetUserId(call, result: result)
break
case "updateUserProperties":
handleUpdateUserProperties(call, result: result)
break
case "setAutoLogAppEventsEnabled":
handleSetAutoLogAppEventsEnabled(call, result: result)
break
Expand Down Expand Up @@ -115,37 +109,12 @@ public class SwiftFacebookAppEventsPlugin: NSObject, FlutterPlugin {
result(nil)
}

private func handleSetUserData(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let arguments = call.arguments as? [String: Any] ?? [String: Any]()

AppEvents.setUserData(arguments["email"] as? String, forType: FBSDKAppEventUserDataType.email)
AppEvents.setUserData(arguments["firstName"] as? String, forType: FBSDKAppEventUserDataType.firstName)
AppEvents.setUserData(arguments["lastName"] as? String, forType: FBSDKAppEventUserDataType.lastName)
AppEvents.setUserData(arguments["phone"] as? String, forType: FBSDKAppEventUserDataType.phone)
AppEvents.setUserData(arguments["dateOfBirth"] as? String, forType: FBSDKAppEventUserDataType.dateOfBirth)
AppEvents.setUserData(arguments["gender"] as? String, forType: FBSDKAppEventUserDataType.gender)
AppEvents.setUserData(arguments["city"] as? String, forType: FBSDKAppEventUserDataType.city)
AppEvents.setUserData(arguments["state"] as? String, forType: FBSDKAppEventUserDataType.state)
AppEvents.setUserData(arguments["zip"] as? String, forType: FBSDKAppEventUserDataType.zip)
AppEvents.setUserData(arguments["country"] as? String, forType: FBSDKAppEventUserDataType.country)

result(nil)
}

private func handleSetUserId(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let id = call.arguments as! String
AppEvents.userID = id
result(nil)
}

private func handleUpdateUserProperties(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
// Seems to have been removed in iOS SDK but only deprecated in the Android SDK
// - iOS removal note: https://github.com/facebook/facebook-ios-sdk/blob/0e1d8774db783d85bd8fc3b53ec96444c048ae42/CHANGELOG.md#removed
// - Android deprecation: https://github.com/facebook/facebook-android-sdk/blob/9da80baea0d23a82ce797e17bd4bc0e0d75b3912/facebook-core/src/main/java/com/facebook/appevents/AppEventsLogger.kt#L633
// Leave this one here for until fully removed in SDK v12
result(nil)
}

private func handleSetAutoLogAppEventsEnabled(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let enabled = call.arguments as! Bool
Settings.isAutoLogAppEventsEnabled = enabled
Expand Down
2 changes: 1 addition & 1 deletion ios/facebook_app_events.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Flutter plugin for Facebook Analytics and App Events
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'FBSDKCoreKit', '~> 11.1'
s.dependency 'FBSDKCoreKit', '~> 12.0'
s.swift_version = '5.0'

s.ios.deployment_target = '9.0'
Expand Down
75 changes: 0 additions & 75 deletions lib/facebook_app_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class FacebookAppEvents {
static const _channel = MethodChannel(channelName);

// See: https://github.com/facebook/facebook-android-sdk/blob/master/facebook-core/src/main/java/com/facebook/appevents/AppEventsConstants.java
static const eventNameActivatedApp = 'fb_mobile_activate_app';
static const eventNameDeactivatedApp = 'fb_mobile_deactivate_app';
static const eventNameCompletedRegistration =
'fb_mobile_complete_registration';
static const eventNameViewedContent = 'fb_mobile_content_view';
Expand Down Expand Up @@ -86,41 +84,6 @@ class FacebookAppEvents {
return _channel.invokeMethod<void>('logEvent', _filterOutNulls(args));
}

/// Sets user data to associate with all app events.
/// All user data are hashed and used to match Facebook user from this
/// instance of an application. The user data will be persisted between
/// application instances.
/// See deprecation note: https://github.com/facebook/facebook-android-sdk/blob/9da80baea0d23a82ce797e17bd4bc0e0d75b3912/facebook-core/src/main/java/com/facebook/appevents/AppEventsLogger.kt#L579
@Deprecated(
'Deprecated starting v0.13.0 of this plugin and will be removed in v12 of Facebook SDK')
Future<void> setUserData({
String? email,
String? firstName,
String? lastName,
String? phone,
String? dateOfBirth,
String? gender,
String? city,
String? state,
String? zip,
String? country,
}) {
final args = <String, dynamic>{
'email': email,
'firstName': firstName,
'lastName': lastName,
'phone': phone,
'dateOfBirth': dateOfBirth,
'gender': gender,
'city': city,
'state': state,
'zip': zip,
'country': country,
};

return _channel.invokeMethod<void>('setUserData', args);
}

/// Logs an app event that tracks that the application was open via Push Notification.
Future<void> logPushNotificationOpen({
required Map<String, dynamic> payload,
Expand All @@ -142,44 +105,6 @@ class FacebookAppEvents {
return _channel.invokeMethod<void>('setUserID', id);
}

/// Update user properties as provided by a map of [parameters]
/// See deprecation note: https://github.com/facebook/facebook-android-sdk/blob/9da80baea0d23a82ce797e17bd4bc0e0d75b3912/facebook-core/src/main/java/com/facebook/appevents/AppEventsLogger.kt#L639
@Deprecated(
'Deprecated starting v0.13.0 of this plugin and will be removed in v12 of Facebook SDK')
Future<void> updateUserProperties({
required Map<String, dynamic> parameters,
String? applicationId,
}) {
final args = <String, dynamic>{
'parameters': parameters,
'applicationId': applicationId,
};

return _channel.invokeMethod<void>('updateUserProperties', args);
}

// Below are shorthand implementations of the predefined app event constants

/// Log this event when an app is being activated.
///
/// See: https://developers.facebook.com/docs/reference/androidsdk/current/facebook/com/facebook/appevents/appeventsconstants.html/#eventnameactivatedapp
/// See deprecation note: https://github.com/facebook/facebook-android-sdk/blob/9da80baea0d23a82ce797e17bd4bc0e0d75b3912/facebook-core/src/main/java/com/facebook/appevents/AppEventsLogger.kt#L381
@Deprecated(
'Deprecated starting v0.13.0 of this plugin and will be removed in v12 of Facebook SDK')
Future<void> logActivatedApp() {
return logEvent(name: eventNameActivatedApp);
}

/// Log this event when an app is being deactivated.
///
/// See: https://developers.facebook.com/docs/reference/androidsdk/current/facebook/com/facebook/appevents/appeventsconstants.html/#eventnamedeactivatedapp
/// See deprecation note: https://github.com/facebook/facebook-android-sdk/blob/9da80baea0d23a82ce797e17bd4bc0e0d75b3912/facebook-core/src/main/java/com/facebook/appevents/AppEventsLogger.kt#L391
@Deprecated(
'Deprecated starting v0.13.0 of this plugin and will be removed in v12 of Facebook SDK')
Future<void> logDeactivatedApp() {
return logEvent(name: eventNameDeactivatedApp);
}

/// Log this event when the user has completed registration with the app.
/// Parameter [registrationMethod] is used to specify the method the user has
/// used to register for the app, e.g. "Facebook", "email", "Google", etc.
Expand Down

0 comments on commit ec5c45e

Please sign in to comment.