FBSDKAppEvents.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. // Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
  2. //
  3. // You are hereby granted a non-exclusive, worldwide, royalty-free license to use,
  4. // copy, modify, and distribute this software in source code or binary form for use
  5. // in connection with the web services and APIs provided by Facebook.
  6. //
  7. // As with any software that integrates with the Facebook platform, your use of
  8. // this software is subject to the Facebook Developer Principles and Policies
  9. // [http://developers.facebook.com/policy/]. This copyright notice shall be
  10. // included in all copies or substantial portions of the software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  14. // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  15. // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  16. // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  17. // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  18. #import <Foundation/Foundation.h>
  19. #if !TARGET_OS_TV
  20. #import <WebKit/WebKit.h>
  21. #endif
  22. #import <FBSDKCoreKit/FBSDKGraphRequestConnection.h>
  23. @class FBSDKAccessToken;
  24. @class FBSDKGraphRequest;
  25. #if __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
  26. /** NSNotificationCenter name indicating a result of a failed log flush attempt. The posted object will be an NSError instance. */
  27. FOUNDATION_EXPORT NSNotificationName const FBSDKAppEventsLoggingResultNotification;
  28. #else
  29. /** NSNotificationCenter name indicating a result of a failed log flush attempt. The posted object will be an NSError instance. */
  30. FOUNDATION_EXPORT NSString *const FBSDKAppEventsLoggingResultNotification;
  31. #endif
  32. /** optional plist key ("FacebookLoggingOverrideAppID") for setting `loggingOverrideAppID` */
  33. FOUNDATION_EXPORT NSString *const FBSDKAppEventsOverrideAppIDBundleKey;
  34. /**
  35. NS_ENUM (NSUInteger, FBSDKAppEventsFlushBehavior)
  36. Specifies when `FBSDKAppEvents` sends log events to the server.
  37. */
  38. typedef NS_ENUM(NSUInteger, FBSDKAppEventsFlushBehavior)
  39. {
  40. /** Flush automatically: periodically (once a minute or every 100 logged events) and always at app reactivation. */
  41. FBSDKAppEventsFlushBehaviorAuto = 0,
  42. /** Only flush when the `flush` method is called. When an app is moved to background/terminated, the
  43. events are persisted and re-established at activation, but they will only be written with an
  44. explicit call to `flush`. */
  45. FBSDKAppEventsFlushBehaviorExplicitOnly,
  46. };
  47. /**
  48. NS_ENUM(NSUInteger, FBSDKProductAvailability)
  49. Specifies product availability for Product Catalog product item update
  50. */
  51. typedef NS_ENUM(NSUInteger, FBSDKProductAvailability)
  52. {
  53. /**
  54. * Item ships immediately
  55. */
  56. FBSDKProductAvailabilityInStock = 0,
  57. /**
  58. * No plan to restock
  59. */
  60. FBSDKProductAvailabilityOutOfStock,
  61. /**
  62. * Available in future
  63. */
  64. FBSDKProductAvailabilityPreOrder,
  65. /**
  66. * Ships in 1-2 weeks
  67. */
  68. FBSDKProductAvailabilityAvailableForOrder,
  69. /**
  70. * Discontinued
  71. */
  72. FBSDKProductAvailabilityDiscontinued,
  73. };
  74. /**
  75. NS_ENUM(NSUInteger, FBSDKProductCondition)
  76. Specifies product condition for Product Catalog product item update
  77. */
  78. typedef NS_ENUM(NSUInteger, FBSDKProductCondition)
  79. {
  80. FBSDKProductConditionNew = 0,
  81. FBSDKProductConditionRefurbished,
  82. FBSDKProductConditionUsed,
  83. };
  84. /**
  85. @methodgroup Predefined event names for logging events common to many apps. Logging occurs through the `logEvent` family of methods on `FBSDKAppEvents`.
  86. Common event parameters are provided in the `FBSDKAppEventsParameterNames*` constants.
  87. */
  88. /** Log this event when the user has achieved a level in the app. */
  89. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameAchievedLevel;
  90. /** Log this event when the user has entered their payment info. */
  91. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameAddedPaymentInfo;
  92. /** Log this event when the user has added an item to their cart. The valueToSum passed to logEvent should be the item's price. */
  93. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameAddedToCart;
  94. /** Log this event when the user has added an item to their wishlist. The valueToSum passed to logEvent should be the item's price. */
  95. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameAddedToWishlist;
  96. /** Log this event when a user has completed registration with the app. */
  97. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameCompletedRegistration;
  98. /** Log this event when the user has completed a tutorial in the app. */
  99. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameCompletedTutorial;
  100. /** Log this event when the user has entered the checkout process. The valueToSum passed to logEvent should be the total price in the cart. */
  101. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameInitiatedCheckout;
  102. /** Log this event when the user has rated an item in the app. The valueToSum passed to logEvent should be the numeric rating. */
  103. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameRated;
  104. /** Log this event when a user has performed a search within the app. */
  105. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameSearched;
  106. /** Log this event when the user has spent app credits. The valueToSum passed to logEvent should be the number of credits spent. */
  107. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameSpentCredits;
  108. /** Log this event when the user has unlocked an achievement in the app. */
  109. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameUnlockedAchievement;
  110. /** Log this event when a user has viewed a form of content in the app. */
  111. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameViewedContent;
  112. /** A telephone/SMS, email, chat or other type of contact between a customer and your business. */
  113. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameContact;
  114. /** The customization of products through a configuration tool or other application your business owns. */
  115. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameCustomizeProduct;
  116. /** The donation of funds to your organization or cause. */
  117. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameDonate;
  118. /** When a person finds one of your locations via web or application, with an intention to visit (example: find product at a local store). */
  119. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameFindLocation;
  120. /** The booking of an appointment to visit one of your locations. */
  121. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameSchedule;
  122. /** The start of a free trial of a product or service you offer (example: trial subscription). */
  123. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameStartTrial;
  124. /** The submission of an application for a product, service or program you offer (example: credit card, educational program or job). */
  125. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameSubmitApplication;
  126. /** The start of a paid subscription for a product or service you offer. */
  127. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameSubscribe;
  128. /** Log this event when the user views an ad. */
  129. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameAdImpression;
  130. /** Log this event when the user clicks an ad. */
  131. FOUNDATION_EXPORT NSString *const FBSDKAppEventNameAdClick;
  132. /**
  133. @methodgroup Predefined event name parameters for common additional information to accompany events logged through the `logEvent` family
  134. of methods on `FBSDKAppEvents`. Common event names are provided in the `FBAppEventName*` constants.
  135. */
  136. /**
  137. * Parameter key used to specify data for the one or more pieces of content being logged about.
  138. * Data should be a JSON encoded string.
  139. * Example:
  140. * "[{\"id\": \"1234\", \"quantity\": 2, \"item_price\": 5.99}, {\"id\": \"5678\", \"quantity\": 1, \"item_price\": 9.99}]"
  141. */
  142. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNameContent;
  143. /** Parameter key used to specify an ID for the specific piece of content being logged about. Could be an EAN, article identifier, etc., depending on the nature of the app. */
  144. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNameContentID;
  145. /** Parameter key used to specify a generic content type/family for the logged event, e.g. "music", "photo", "video". Options to use will vary based upon what the app is all about. */
  146. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNameContentType;
  147. /** Parameter key used to specify currency used with logged event. E.g. "USD", "EUR", "GBP". See ISO-4217 for specific values. One reference for these is <http://en.wikipedia.org/wiki/ISO_4217>. */
  148. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNameCurrency;
  149. /** Parameter key used to specify a description appropriate to the event being logged. E.g., the name of the achievement unlocked in the `FBAppEventNameAchievementUnlocked` event. */
  150. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNameDescription;
  151. /** Parameter key used to specify the level achieved in a `FBAppEventNameAchieved` event. */
  152. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNameLevel;
  153. /** Parameter key used to specify the maximum rating available for the `FBAppEventNameRate` event. E.g., "5" or "10". */
  154. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNameMaxRatingValue;
  155. /** Parameter key used to specify how many items are being processed for an `FBAppEventNameInitiatedCheckout` or `FBAppEventNamePurchased` event. */
  156. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNameNumItems;
  157. /** Parameter key used to specify whether payment info is available for the `FBAppEventNameInitiatedCheckout` event. `FBSDKAppEventParameterValueYes` and `FBSDKAppEventParameterValueNo` are good canonical values to use for this parameter. */
  158. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNamePaymentInfoAvailable;
  159. /** Parameter key used to specify method user has used to register for the app, e.g., "Facebook", "email", "Twitter", etc */
  160. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNameRegistrationMethod;
  161. /** Parameter key used to specify the string provided by the user for a search operation. */
  162. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNameSearchString;
  163. /** Parameter key used to specify whether the activity being logged about was successful or not. `FBSDKAppEventParameterValueYes` and `FBSDKAppEventParameterValueNo` are good canonical values to use for this parameter. */
  164. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNameSuccess;
  165. /**
  166. @methodgroup Predefined event name parameters for common additional information to accompany events logged through the `logProductItem` method on `FBSDKAppEvents`.
  167. */
  168. /** Parameter key used to specify the product item's custom label 0. */
  169. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductCustomLabel0;
  170. /** Parameter key used to specify the product item's custom label 1. */
  171. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductCustomLabel1;
  172. /** Parameter key used to specify the product item's custom label 2. */
  173. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductCustomLabel2;
  174. /** Parameter key used to specify the product item's custom label 3. */
  175. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductCustomLabel3;
  176. /** Parameter key used to specify the product item's custom label 4. */
  177. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductCustomLabel4;
  178. /** Parameter key used to specify the product item's AppLink app URL for iOS. */
  179. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkIOSUrl;
  180. /** Parameter key used to specify the product item's AppLink app ID for iOS App Store. */
  181. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkIOSAppStoreID;
  182. /** Parameter key used to specify the product item's AppLink app name for iOS. */
  183. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkIOSAppName;
  184. /** Parameter key used to specify the product item's AppLink app URL for iPhone. */
  185. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkIPhoneUrl;
  186. /** Parameter key used to specify the product item's AppLink app ID for iPhone App Store. */
  187. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkIPhoneAppStoreID;
  188. /** Parameter key used to specify the product item's AppLink app name for iPhone. */
  189. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkIPhoneAppName;
  190. /** Parameter key used to specify the product item's AppLink app URL for iPad. */
  191. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkIPadUrl;
  192. /** Parameter key used to specify the product item's AppLink app ID for iPad App Store. */
  193. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkIPadAppStoreID;
  194. /** Parameter key used to specify the product item's AppLink app name for iPad. */
  195. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkIPadAppName;
  196. /** Parameter key used to specify the product item's AppLink app URL for Android. */
  197. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkAndroidUrl;
  198. /** Parameter key used to specify the product item's AppLink fully-qualified package name for intent generation. */
  199. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkAndroidPackage;
  200. /** Parameter key used to specify the product item's AppLink app name for Android. */
  201. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkAndroidAppName;
  202. /** Parameter key used to specify the product item's AppLink app URL for Windows Phone. */
  203. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkWindowsPhoneUrl;
  204. /** Parameter key used to specify the product item's AppLink app ID, as a GUID, for App Store. */
  205. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkWindowsPhoneAppID;
  206. /** Parameter key used to specify the product item's AppLink app name for Windows Phone. */
  207. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterProductAppLinkWindowsPhoneAppName;
  208. /*
  209. @methodgroup Predefined values to assign to event parameters that accompany events logged through the `logEvent` family
  210. of methods on `FBSDKAppEvents`. Common event parameters are provided in the `FBSDKAppEventParameterName*` constants.
  211. */
  212. /** Yes-valued parameter value to be used with parameter keys that need a Yes/No value */
  213. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterValueYes;
  214. /** No-valued parameter value to be used with parameter keys that need a Yes/No value */
  215. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterValueNo;
  216. /** Parameter key used to specify the type of ad in an FBSDKAppEventNameAdImpression
  217. * or FBSDKAppEventNameAdClick event.
  218. * E.g. "banner", "interstitial", "rewarded_video", "native" */
  219. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNameAdType;
  220. /** Parameter key used to specify the unique ID for all events within a subscription
  221. * in an FBSDKAppEventNameSubscribe or FBSDKAppEventNameStartTrial event. */
  222. FOUNDATION_EXPORT NSString *const FBSDKAppEventParameterNameOrderID;
  223. /**
  224. Client-side event logging for specialized application analytics available through Facebook App Insights
  225. and for use with Facebook Ads conversion tracking and optimization.
  226. The `FBSDKAppEvents` static class has a few related roles:
  227. + Logging predefined and application-defined events to Facebook App Insights with a
  228. numeric value to sum across a large number of events, and an optional set of key/value
  229. parameters that define "segments" for this event (e.g., 'purchaserStatus' : 'frequent', or
  230. 'gamerLevel' : 'intermediate')
  231. + Logging events to later be used for ads optimization around lifetime value.
  232. + Methods that control the way in which events are flushed out to the Facebook servers.
  233. Here are some important characteristics of the logging mechanism provided by `FBSDKAppEvents`:
  234. + Events are not sent immediately when logged. They're cached and flushed out to the Facebook servers
  235. in a number of situations:
  236. - when an event count threshold is passed (currently 100 logged events).
  237. - when a time threshold is passed (currently 15 seconds).
  238. - when an app has gone to background and is then brought back to the foreground.
  239. + Events will be accumulated when the app is in a disconnected state, and sent when the connection is
  240. restored and one of the above 'flush' conditions are met.
  241. + The `FBSDKAppEvents` class is thread-safe in that events may be logged from any of the app's threads.
  242. + The developer can set the `flushBehavior` on `FBSDKAppEvents` to force the flushing of events to only
  243. occur on an explicit call to the `flush` method.
  244. + The developer can turn on console debug output for event logging and flushing to the server by using
  245. the `FBSDKLoggingBehaviorAppEvents` value in `[FBSettings setLoggingBehavior:]`.
  246. Some things to note when logging events:
  247. + There is a limit on the number of unique event names an app can use, on the order of 1000.
  248. + There is a limit to the number of unique parameter names in the provided parameters that can
  249. be used per event, on the order of 25. This is not just for an individual call, but for all
  250. invocations for that eventName.
  251. + Event names and parameter names (the keys in the NSDictionary) must be between 2 and 40 characters, and
  252. must consist of alphanumeric characters, _, -, or spaces.
  253. + The length of each parameter value can be no more than on the order of 100 characters.
  254. */
  255. @interface FBSDKAppEvents : NSObject
  256. /*
  257. * Basic event logging
  258. */
  259. /**
  260. Log an event with just an eventName.
  261. @param eventName The name of the event to record. Limitations on number of events and name length
  262. are given in the `FBSDKAppEvents` documentation.
  263. */
  264. + (void)logEvent:(NSString *)eventName;
  265. /**
  266. Log an event with an eventName and a numeric value to be aggregated with other events of this name.
  267. @param eventName The name of the event to record. Limitations on number of events and name length
  268. are given in the `FBSDKAppEvents` documentation. Common event names are provided in `FBAppEventName*` constants.
  269. @param valueToSum Amount to be aggregated into all events of this eventName, and App Insights will report
  270. the cumulative and average value of this amount.
  271. */
  272. + (void)logEvent:(NSString *)eventName
  273. valueToSum:(double)valueToSum;
  274. /**
  275. Log an event with an eventName and a set of key/value pairs in the parameters dictionary.
  276. Parameter limitations are described above.
  277. @param eventName The name of the event to record. Limitations on number of events and name construction
  278. are given in the `FBSDKAppEvents` documentation. Common event names are provided in `FBAppEventName*` constants.
  279. @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must
  280. be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of
  281. parameters and name construction are given in the `FBSDKAppEvents` documentation. Commonly used parameter names
  282. are provided in `FBSDKAppEventParameterName*` constants.
  283. */
  284. + (void)logEvent:(NSString *)eventName
  285. parameters:(NSDictionary *)parameters;
  286. /**
  287. Log an event with an eventName, a numeric value to be aggregated with other events of this name,
  288. and a set of key/value pairs in the parameters dictionary.
  289. @param eventName The name of the event to record. Limitations on number of events and name construction
  290. are given in the `FBSDKAppEvents` documentation. Common event names are provided in `FBAppEventName*` constants.
  291. @param valueToSum Amount to be aggregated into all events of this eventName, and App Insights will report
  292. the cumulative and average value of this amount.
  293. @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must
  294. be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of
  295. parameters and name construction are given in the `FBSDKAppEvents` documentation. Commonly used parameter names
  296. are provided in `FBSDKAppEventParameterName*` constants.
  297. */
  298. + (void)logEvent:(NSString *)eventName
  299. valueToSum:(double)valueToSum
  300. parameters:(NSDictionary *)parameters;
  301. /**
  302. Log an event with an eventName, a numeric value to be aggregated with other events of this name,
  303. and a set of key/value pairs in the parameters dictionary. Providing session lets the developer
  304. target a particular <FBSession>. If nil is provided, then `[FBSession activeSession]` will be used.
  305. @param eventName The name of the event to record. Limitations on number of events and name construction
  306. are given in the `FBSDKAppEvents` documentation. Common event names are provided in `FBAppEventName*` constants.
  307. @param valueToSum Amount to be aggregated into all events of this eventName, and App Insights will report
  308. the cumulative and average value of this amount. Note that this is an NSNumber, and a value of `nil` denotes
  309. that this event doesn't have a value associated with it for summation.
  310. @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must
  311. be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of
  312. parameters and name construction are given in the `FBSDKAppEvents` documentation. Commonly used parameter names
  313. are provided in `FBSDKAppEventParameterName*` constants.
  314. @param accessToken The optional access token to log the event as.
  315. */
  316. + (void)logEvent:(NSString *)eventName
  317. valueToSum:(NSNumber *)valueToSum
  318. parameters:(NSDictionary *)parameters
  319. accessToken:(FBSDKAccessToken *)accessToken;
  320. /*
  321. * Purchase logging
  322. */
  323. /**
  324. Log a purchase of the specified amount, in the specified currency.
  325. @param purchaseAmount Purchase amount to be logged, as expressed in the specified currency. This value
  326. will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346).
  327. @param currency Currency, is denoted as, e.g. "USD", "EUR", "GBP". See ISO-4217 for
  328. specific values. One reference for these is <http://en.wikipedia.org/wiki/ISO_4217>.
  329. This event immediately triggers a flush of the `FBSDKAppEvents` event queue, unless the `flushBehavior` is set
  330. to `FBSDKAppEventsFlushBehaviorExplicitOnly`.
  331. */
  332. + (void)logPurchase:(double)purchaseAmount
  333. currency:(NSString *)currency;
  334. /**
  335. Log a purchase of the specified amount, in the specified currency, also providing a set of
  336. additional characteristics describing the purchase.
  337. @param purchaseAmount Purchase amount to be logged, as expressed in the specified currency.This value
  338. will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346).
  339. @param currency Currency, is denoted as, e.g. "USD", "EUR", "GBP". See ISO-4217 for
  340. specific values. One reference for these is <http://en.wikipedia.org/wiki/ISO_4217>.
  341. @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must
  342. be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of
  343. parameters and name construction are given in the `FBSDKAppEvents` documentation. Commonly used parameter names
  344. are provided in `FBSDKAppEventParameterName*` constants.
  345. This event immediately triggers a flush of the `FBSDKAppEvents` event queue, unless the `flushBehavior` is set
  346. to `FBSDKAppEventsFlushBehaviorExplicitOnly`.
  347. */
  348. + (void)logPurchase:(double)purchaseAmount
  349. currency:(NSString *)currency
  350. parameters:(NSDictionary *)parameters;
  351. /**
  352. Log a purchase of the specified amount, in the specified currency, also providing a set of
  353. additional characteristics describing the purchase, as well as an <FBSession> to log to.
  354. @param purchaseAmount Purchase amount to be logged, as expressed in the specified currency.This value
  355. will be rounded to the thousandths place (e.g., 12.34567 becomes 12.346).
  356. @param currency Currency, is denoted as, e.g. "USD", "EUR", "GBP". See ISO-4217 for
  357. specific values. One reference for these is <http://en.wikipedia.org/wiki/ISO_4217>.
  358. @param parameters Arbitrary parameter dictionary of characteristics. The keys to this dictionary must
  359. be NSString's, and the values are expected to be NSString or NSNumber. Limitations on the number of
  360. parameters and name construction are given in the `FBSDKAppEvents` documentation. Commonly used parameter names
  361. are provided in `FBSDKAppEventParameterName*` constants.
  362. @param accessToken The optional access token to log the event as.
  363. This event immediately triggers a flush of the `FBSDKAppEvents` event queue, unless the `flushBehavior` is set
  364. to `FBSDKAppEventsFlushBehaviorExplicitOnly`.
  365. */
  366. + (void)logPurchase:(double)purchaseAmount
  367. currency:(NSString *)currency
  368. parameters:(NSDictionary *)parameters
  369. accessToken:(FBSDKAccessToken *)accessToken;
  370. /*
  371. * Push Notifications Logging
  372. */
  373. /**
  374. Log an app event that tracks that the application was open via Push Notification.
  375. @param payload Notification payload received via `UIApplicationDelegate`.
  376. */
  377. + (void)logPushNotificationOpen:(NSDictionary *)payload;
  378. /**
  379. Log an app event that tracks that a custom action was taken from a push notification.
  380. @param payload Notification payload received via `UIApplicationDelegate`.
  381. @param action Name of the action that was taken.
  382. */
  383. + (void)logPushNotificationOpen:(NSDictionary *)payload action:(NSString *)action;
  384. /**
  385. Uploads product catalog product item as an app event
  386. @param itemID Unique ID for the item. Can be a variant for a product.
  387. Max size is 100.
  388. @param availability If item is in stock. Accepted values are:
  389. in stock - Item ships immediately
  390. out of stock - No plan to restock
  391. preorder - Available in future
  392. available for order - Ships in 1-2 weeks
  393. discontinued - Discontinued
  394. @param condition Product condition: new, refurbished or used.
  395. @param description Short text describing product. Max size is 5000.
  396. @param imageLink Link to item image used in ad.
  397. @param link Link to merchant's site where someone can buy the item.
  398. @param title Title of item.
  399. @param priceAmount Amount of purchase, in the currency specified by the 'currency'
  400. parameter. This value will be rounded to the thousandths place
  401. (e.g., 12.34567 becomes 12.346).
  402. @param currency Currency used to specify the amount.
  403. E.g. "USD", "EUR", "GBP". See ISO-4217 for specific values. One reference for these is <http://en.wikipedia.org/wiki/ISO_4217>
  404. @param gtin Global Trade Item Number including UPC, EAN, JAN and ISBN
  405. @param mpn Unique manufacture ID for product
  406. @param brand Name of the brand
  407. Note: Either gtin, mpn or brand is required.
  408. @param parameters Optional fields for deep link specification.
  409. */
  410. + (void)logProductItem:(NSString *)itemID
  411. availability:(FBSDKProductAvailability)availability
  412. condition:(FBSDKProductCondition)condition
  413. description:(NSString *)description
  414. imageLink:(NSString *)imageLink
  415. link:(NSString *)link
  416. title:(NSString *)title
  417. priceAmount:(double)priceAmount
  418. currency:(NSString *)currency
  419. gtin:(NSString *)gtin
  420. mpn:(NSString *)mpn
  421. brand:(NSString *)brand
  422. parameters:(NSDictionary *)parameters;
  423. /**
  424. Notifies the events system that the app has launched and, when appropriate, logs an "activated app" event.
  425. This function is called automatically from FBSDKApplicationDelegate applicationDidBecomeActive, unless
  426. one overrides 'FacebookAutoLogAppEventsEnabled' key to false in the project info plist file.
  427. In case 'FacebookAutoLogAppEventsEnabled' is set to false, then it should typically be placed in the
  428. app delegates' `applicationDidBecomeActive:` method.
  429. This method also takes care of logging the event indicating the first time this app has been launched, which, among other things, is used to
  430. track user acquisition and app install ads conversions.
  431. `activateApp` will not log an event on every app launch, since launches happen every time the app is backgrounded and then foregrounded.
  432. "activated app" events will be logged when the app has not been active for more than 60 seconds. This method also causes a "deactivated app"
  433. event to be logged when sessions are "completed", and these events are logged with the session length, with an indication of how much
  434. time has elapsed between sessions, and with the number of background/foreground interruptions that session had. This data
  435. is all visible in your app's App Events Insights.
  436. */
  437. + (void)activateApp;
  438. /*
  439. * Push Notifications Registration and Uninstall Tracking
  440. */
  441. /**
  442. Sets and sends device token to register the current application for push notifications.
  443. Sets and sends a device token from `NSData` representation that you get from `UIApplicationDelegate.-application:didRegisterForRemoteNotificationsWithDeviceToken:`.
  444. @param deviceToken Device token data.
  445. */
  446. + (void)setPushNotificationsDeviceToken:(NSData *)deviceToken;
  447. /**
  448. Sets and sends device token string to register the current application for push notifications.
  449. Sets and sends a device token string
  450. @param deviceTokenString Device token string.
  451. */
  452. + (void)setPushNotificationsDeviceTokenString:(NSString *)deviceTokenString;
  453. /*
  454. * Control over event batching/flushing
  455. */
  456. /**
  457. Get the current event flushing behavior specifying when events are sent back to Facebook servers.
  458. */
  459. + (FBSDKAppEventsFlushBehavior)flushBehavior;
  460. /**
  461. Set the current event flushing behavior specifying when events are sent back to Facebook servers.
  462. @param flushBehavior The desired `FBSDKAppEventsFlushBehavior` to be used.
  463. */
  464. + (void)setFlushBehavior:(FBSDKAppEventsFlushBehavior)flushBehavior;
  465. /**
  466. Set the 'override' App ID for App Event logging.
  467. In some cases, apps want to use one Facebook App ID for login and social presence and another
  468. for App Event logging. (An example is if multiple apps from the same company share an app ID for login, but
  469. want distinct logging.) By default, this value is `nil`, and defers to the `FBSDKAppEventsOverrideAppIDBundleKey`
  470. plist value. If that's not set, it defaults to `[FBSDKSettings appID]`.
  471. This should be set before any other calls are made to `FBSDKAppEvents`. Thus, you should set it in your application
  472. delegate's `application:didFinishLaunchingWithOptions:` delegate.
  473. @param appID The Facebook App ID to be used for App Event logging.
  474. */
  475. + (void)setLoggingOverrideAppID:(NSString *)appID;
  476. /**
  477. Get the 'override' App ID for App Event logging.
  478. @see setLoggingOverrideAppID:
  479. */
  480. + (NSString *)loggingOverrideAppID;
  481. /**
  482. Explicitly kick off flushing of events to Facebook. This is an asynchronous method, but it does initiate an immediate
  483. kick off. Server failures will be reported through the NotificationCenter with notification ID `FBSDKAppEventsLoggingResultNotification`.
  484. */
  485. + (void)flush;
  486. /**
  487. Creates a request representing the Graph API call to retrieve a Custom Audience "third party ID" for the app's Facebook user.
  488. Callers will send this ID back to their own servers, collect up a set to create a Facebook Custom Audience with,
  489. and then use the resultant Custom Audience to target ads.
  490. @param accessToken The access token to use to establish the user's identity for users logged into Facebook through this app.
  491. If `nil`, then the `[FBSDKAccessToken currentAccessToken]` is used.
  492. The JSON in the request's response will include an "custom_audience_third_party_id" key/value pair, with the value being the ID retrieved.
  493. This ID is an encrypted encoding of the Facebook user's ID and the invoking Facebook app ID.
  494. Multiple calls with the same user will return different IDs, thus these IDs cannot be used to correlate behavior
  495. across devices or applications, and are only meaningful when sent back to Facebook for creating Custom Audiences.
  496. The ID retrieved represents the Facebook user identified in the following way: if the specified access token is valid,
  497. the ID will represent the user associated with that token; otherwise the ID will represent the user logged into the
  498. native Facebook app on the device. If there is no native Facebook app, no one is logged into it, or the user has opted out
  499. at the iOS level from ad tracking, then a `nil` ID will be returned.
  500. This method returns `nil` if either the user has opted-out (via iOS) from Ad Tracking, the app itself has limited event usage
  501. via the `[FBSDKSettings limitEventAndDataUsage]` flag, or a specific Facebook user cannot be identified.
  502. */
  503. + (FBSDKGraphRequest *)requestForCustomAudienceThirdPartyIDWithAccessToken:(FBSDKAccessToken *)accessToken;
  504. /*
  505. Sets a custom user ID to associate with all app events.
  506. The userID is persisted until it is cleared by passing nil.
  507. */
  508. + (void)setUserID:(NSString *)userID;
  509. /*
  510. Clears the custom user ID to associate with all app events.
  511. */
  512. + (void)clearUserID;
  513. /*
  514. Returns the set custom user ID.
  515. */
  516. + (NSString *)userID;
  517. /*
  518. Sets custom user data to associate with all app events. All user data are hashed
  519. and used to match Facebook user from this instance of an application.
  520. The user data will be persisted between application instances.
  521. @param userData user data to identify the user. User data should be formated as
  522. a NSDictionary of data type name and value.
  523. Supported data types and names are:
  524. Email: em
  525. First Name: fn
  526. Last Name: ln
  527. Phone: ph
  528. Date of Birth: db
  529. Gender: ge
  530. City: ct
  531. State: st
  532. Zip: zp
  533. Country: country
  534. */
  535. + (void)setUserData:(NSDictionary *)userData
  536. DEPRECATED_MSG_ATTRIBUTE("Renamed `setUserEmail:firstName: ...`");
  537. /*
  538. Sets custom user data to associate with all app events. All user data are hashed
  539. and used to match Facebook user from this instance of an application.
  540. The user data will be persisted between application instances.
  541. @param email user's email
  542. @param firstName user's first name
  543. @param lastName user's last name
  544. @param phone user's phone
  545. @param dateOfBirth user's date of birth
  546. @param gender user's gender
  547. @param city user's city
  548. @param state user's state
  549. @param zip user's zip
  550. @param country user's country
  551. */
  552. + (void)setUserEmail:(NSString *)email
  553. firstName:(NSString *)firstName
  554. lastName:(NSString *)lastName
  555. phone:(NSString *)phone
  556. dateOfBirth:(NSString *)dateOfBirth
  557. gender:(NSString *)gender
  558. city:(NSString *)city
  559. state:(NSString *)state
  560. zip:(NSString *)zip
  561. country:(NSString *)country;
  562. /*
  563. Returns the set user data else nil
  564. */
  565. + (NSString *)getUserData;
  566. /*
  567. Clears the current user data
  568. */
  569. + (void)clearUserData;
  570. /*
  571. Sends a request to update the properties for the current user, set by `setUserID:`
  572. You must call `FBSDKAppEvents setUserID:` before making this call.
  573. @param properties the custom user properties
  574. @param handler the optional completion handler
  575. */
  576. + (void)updateUserProperties:(NSDictionary *)properties handler:(FBSDKGraphRequestHandler)handler;
  577. #if !TARGET_OS_TV
  578. /*
  579. Intended to be used as part of a hybrid webapp.
  580. If you call this method, the FB SDK will inject a new JavaScript object into your webview.
  581. If the FB Pixel is used within the webview, and references the app ID of this app,
  582. then it will detect the presence of this injected JavaScript object
  583. and pass Pixel events back to the FB SDK for logging using the AppEvents framework.
  584. @param webView The webview to augment with the additional JavaScript behaviour
  585. */
  586. + (void)augmentHybridWKWebView:(WKWebView *)webView;
  587. #endif
  588. /*
  589. * Unity helper functions
  590. */
  591. /**
  592. Set if the Unity is already initialized
  593. @param isUnityInit whether Unity is initialized.
  594. */
  595. + (void)setIsUnityInit:(BOOL)isUnityInit;
  596. /*
  597. Send event binding to Unity
  598. */
  599. + (void)sendEventBindingsToUnity;
  600. @end