Code Monkey home page Code Monkey logo

facebook_event's Introduction

facebook_event

pub package

Flutter plugin for Facebook Event and Analytics.

Facebook Events is a feature that can help you organize social gatherings via Facebook. You get a dedicated page for providing all the details of your event plus a range of tools to notify friends about it and keep track of who's going. Facebook Events are different from Facebook Groups and Facebook Pages.

Facebook Analytics is a robust tool that lets marketers explore users' interactions with advanced goal paths and sales funnels for Facebook ads. In this article, you'll discover how to get started with Facebook Analytics.

Installation

You must first create an app at Facebook for developers: https://developers.facebook.com/

Get your app id (referred to as [APP_ID] below)

Android

Read through the "Getting Started with App Events for Android" tutuorial and in particular, follow step 2 by adding the following into /app/res/values/strings.xml (or into respective debug or release build flavor)

After that, add that string resource reference to your main AndroidManifest.xml file, directly under the <application> tag.

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

Example Code

Add code in your android project MainActivity.kt

setAutoLogAppEventsEnabled(true)
FacebookSdk.setAutoInitEnabled(true)
FacebookSdk.fullyInitialize()
setAdvertiserIDCollectionEnabled(true)
FacebookSdk.setIsDebugEnabled(true);
FacebookSdk.addLoggingBehavior(LoggingBehavior.APP_EVENTS);

Example Code

iOS

Read through the "Getting Started with App Events for iOS" tutuorial and in particular, follow step 4 by opening info.plist "As Source Code" and add the following

If your code does not have CFBundleURLTypes, add the following just before the final </dict> element:

<key>CFBundleURLTypes</key>
<array>
  <dict>
  <key>CFBundleURLSchemes</key>
  <array>
    <string>fb[APP_ID]</string>
  </array>
  </dict>
</array>
<key>FacebookAppID</key>
<string>[APP_ID]</string>
<key>FacebookDisplayName</key>
<string>[APP_NAME]</string>

If your code already contains CFBundleURLTypes, insert the following:

<array>
 <dict>
 <key>CFBundleURLSchemes</key>
 <array>
   <string>fb[APP_ID]</string>
 </array>
 </dict>
</array>
<key>FacebookAppID</key>
<string>[APP_ID]</string>
<key>FacebookDisplayName</key>
<string>[APP_NAME]</string>

Example Code

Add code in your android project AppDelegate.swift

ApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
AppEvents.activateApp()
AppEvents.logEvent(AppEvents.Name.init(rawValue: "Opened App Main VC"))

Example Code

Get Android HashKey

final facebookEvent = FacebookEvent();
String hashKey='Null';

@override
void initState() {
    // TODO: implement initState
    super.initState();
    if(Platform.isAndroid)
      getHashKey();
}

void getHashKey()async{
    hashKey= await facebookEvent.getAndroidHashKey();
    print(hashKey);
}

All Events

final facebookEvent = FacebookEvent();

// Get facebook application id
facebookEvent.getApplicationId();

/// An app is being activated, typically in the AppDelegate's applicationDidBecomeActive.
facebookEvent.logActivatedApp();

// This event when an app is being deactivated.
facebookEvent.logDeactivatedApp();

// Re-enables auto logging of app events after user consent
facebookEvent.setAutoLogAppEventsEnabled(true);

// Submit user details
facebookEvent.setUserData(
  email:'email',
  firstName:'first name',
  lastName:'last name',
  phone:'phone number',
  dateOfBirth:'dob',
  gender:'gender',
  city:'city',
  state:'state',
  zip:'zip',
  country:'country',
);

// Submit custom event
facebookEvent.logEvent(
    name: 'name',
    body: {'key':'value'},
    valueToSum: 0
);

// Submit contact details
facebookEvent.logContactEvent(contact: 'number');

// A user has viewed a form of content in the app.
facebookEvent.logViewContent(
  content: {'key':'value'},
  id: 'id',
  type: 'type'
);

// The user has completed a purchase. The FB.LogPurchase method is a shortcut for logging this event. specified currency.
facebookEvent.logPurchase(
  amount: 0,
  currency: 'USD',
  body: {'key':'value'}
);

// The user has achieved a level in the app.
facebookEvent.logAchieveLevelEvent(
  level: 'level'
);

// The user has entered their payment info.
facebookEvent.logAddPaymentInfoEvent(
  success: true
);

// The user has added an item to their cart. The valueToSum passed should be the item's price.
facebookEvent.logAddToCartEvent(
  price:0,
  contentData: 'contentData',
  contentType: 'contentType',
  contentId: 'contentId',
  currency: 'USD'
);

// This event when the user has completed registration with the app.
// A user has completed registration with the app.
facebookEvent.logCompleteRegistrationEvent(
  registrationMethod:'registrationMethod',
  name: 'name',
  currency: 'USD'
);

// The user has entered the checkout process. The valueToSum passed should be the total price in the cart.
facebookEvent.logInitiateCheckoutEvent(
  totalPrice:0,
  contentData: 'contentData',
  contentType: 'contentType',
  contentId: 'contentId',
  currency: 'USD',
  numItems: 1,
  paymentInfoAvailable: true
);

// The user has rated an item in the app. The valueToSum passed should be the numeric rating.
facebookEvent.logRateEvent(
  ratingGiven:5,
  contentData: 'contentData',
  contentType: 'contentType',
  contentId: 'contentId',
  maxRatingValue: 5
);

Documentation

You will find all the FB.LogAppEvent details here.

facebook_event's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

facebook_event's Issues

Type mismatch: inferred type is String? but String was expected (Android)

Launching lib/main.dart on Android SDK built for x86 in debug mode...
lib/main.dart:1
e: /Users/mac/development/flutter/.pub-cache/hosted/pub.dartlang.org/facebook_event-0.0.6/android/src/main/kotlin/com/faisal/flutter/facebook_event/FacebookEventPlugin.kt: (244, 31): Type mismatch: inferred type is String? but String was expected
e: /Users/mac/development/flutter/.pub-cache/hosted/pub.dartlang.org/facebook_event-0.0.6/android/src/main/kotlin/com/faisal/flutter/facebook_event/FacebookEventPlugin.kt: (246, 31): Type mismatch: inferred type is String? but String was expected

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':facebook_event:compileDebugKotlin'.

Compilation error. See log for more details

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1m 19s

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.