@@ -30,6 +30,15 @@ For more information please check the following pages:
3030 - [ iOS] ( #ios )
3131* [ ProGuard Rules for Android] ( #proguard-rules-for-android )
3232* [ Full Code Example] ( #full-code-example )
33+ * [ Purchase Revenue Data Sources] ( #purchase-revenue-data-sources )
34+ - [ iOS Data Sources] ( #ios-data-sources )
35+ - [ StoreKit1 Data Source] ( #storekit1-data-source )
36+ - [ StoreKit2 Data Source] ( #storekit2-data-source )
37+ - [ Android Data Sources] ( #android-data-sources )
38+ - [ Subscription Purchase Data Source] ( #subscription-purchase-data-source )
39+ - [ In-App Purchase Data Source] ( #in-app-purchase-data-source )
40+ - [ Platform-Specific Implementation] ( #platform-specific-implementation )
41+ - [ Important Notes] ( #important-notes )
3342
3443## <a id =" important-note " ></a >Important Note ⚠️ ⚠️
3544
@@ -377,4 +386,156 @@ const handleValidationSuccess = (validationResult) => {
377386 AppsFlyerPurchaseConnector .startObservingTransactions ();
378387
379388// AppsFlyerPurchaseConnector.stopObservingTransactions();
380- ```
389+ ```
390+
391+ ## <a id =" purchase-revenue-data-sources " ></a >Purchase Revenue Data Sources
392+
393+ The Purchase Connector allows you to add additional parameters to your purchase events through data sources. These parameters will be included in the purchase events sent to AppsFlyer.
394+
395+ ### <a id =" ios-data-sources " ></a >iOS Data Sources
396+
397+ For iOS, there are two types of data sources:
398+
399+ 1 . ** StoreKit1 Data Source** : For traditional in-app purchases
400+ 2 . ** StoreKit2 Data Source** : For iOS 15.0 and later, supporting the newer StoreKit2 framework
401+
402+ #### StoreKit1 Data Source
403+ ``` javascript
404+ // Set additional parameters for StoreKit1 purchases
405+ AppsFlyerPurchaseConnector .setPurchaseRevenueDataSource ({
406+ additionalParameters: {
407+ user_id: ' 12345' ,
408+ user_type: ' premium' ,
409+ purchase_source: ' app_store' ,
410+ custom_param1: ' value1' ,
411+ custom_param2: ' value2'
412+ }
413+ });
414+ ```
415+
416+ #### StoreKit2 Data Source
417+ ``` javascript
418+ // Set additional parameters for StoreKit2 purchases
419+ AppsFlyerPurchaseConnector .setPurchaseRevenueDataSourceStoreKit2 ({
420+ products: [
421+ { product_id: ' com.app.subscription.monthly' },
422+ { product_id: ' com.app.subscription.yearly' }
423+ ],
424+ transactions: [
425+ { transaction_id: ' transaction123' },
426+ { transaction_id: ' transaction456' }
427+ ]
428+ });
429+ ```
430+
431+ ### <a id =" android-data-sources " ></a >Android Data Sources
432+
433+ For Android, there are two types of data sources:
434+
435+ 1 . ** Subscription Purchase Data Source** : For subscription purchases
436+ 2 . ** In-App Purchase Data Source** : For one-time in-app purchases
437+
438+ #### Subscription Purchase Data Source
439+ ``` javascript
440+ // Set additional parameters for subscription purchases
441+ AppsFlyerPurchaseConnector .setSubscriptionPurchaseEventDataSource ({
442+ additionalParameters: {
443+ user_id: ' 12345' ,
444+ user_type: ' premium' ,
445+ purchase_source: ' play_store' ,
446+ custom_param1: ' value1' ,
447+ custom_param2: ' value2'
448+ }
449+ });
450+ ```
451+
452+ #### In-App Purchase Data Source
453+ ``` javascript
454+ // Set additional parameters for in-app purchases
455+ AppsFlyerPurchaseConnector .setInAppPurchaseEventDataSource ({
456+ additionalParameters: {
457+ user_id: ' 12345' ,
458+ user_type: ' premium' ,
459+ purchase_source: ' play_store' ,
460+ custom_param1: ' value1' ,
461+ custom_param2: ' value2'
462+ }
463+ });
464+ ```
465+
466+ ### <a id =" platform-specific-implementation " ></a >Platform-Specific Implementation
467+
468+ When implementing these data sources in your app, you should consider the platform differences:
469+
470+ ``` javascript
471+ import { Platform } from ' react-native' ;
472+ import AppsFlyerPurchaseConnector from ' react-native-appsflyer-plugin' ;
473+
474+ const setupPurchaseDataSources = () => {
475+ if (Platform .OS === ' ios' ) {
476+ // iOS StoreKit1 data source
477+ AppsFlyerPurchaseConnector .setPurchaseRevenueDataSource ({
478+ additionalParameters: {
479+ user_id: ' 12345' ,
480+ user_type: ' premium' ,
481+ purchase_source: ' app_store'
482+ }
483+ });
484+
485+ // iOS StoreKit2 data source (iOS 15.0+)
486+ AppsFlyerPurchaseConnector .setPurchaseRevenueDataSourceStoreKit2 ({
487+ products: [
488+ { product_id: ' com.app.subscription.monthly' }
489+ ],
490+ transactions: [
491+ { transaction_id: ' transaction123' }
492+ ]
493+ });
494+ } else if (Platform .OS === ' android' ) {
495+ // Android subscription data source
496+ AppsFlyerPurchaseConnector .setSubscriptionPurchaseEventDataSource ({
497+ additionalParameters: {
498+ user_id: ' 12345' ,
499+ user_type: ' premium' ,
500+ purchase_source: ' play_store'
501+ }
502+ });
503+
504+ // Android in-app purchase data source
505+ AppsFlyerPurchaseConnector .setInAppPurchaseEventDataSource ({
506+ additionalParameters: {
507+ user_id: ' 12345' ,
508+ user_type: ' premium' ,
509+ purchase_source: ' play_store'
510+ }
511+ });
512+ }
513+ };
514+ ```
515+
516+ ### <a id =" important-notes " ></a >Important Notes
517+
518+ 1 . ** iOS StoreKit2** : The StoreKit2 data source is only available on iOS 15.0 and later. Make sure to check the iOS version before using it.
519+
520+ 2 . ** Parameter Structure** :
521+ - For iOS StoreKit1 and Android, use the ` additionalParameters ` object to add custom parameters
522+ - For iOS StoreKit2, use the ` products ` and ` transactions ` arrays to specify product and transaction IDs
523+
524+ 3 . ** Timing** : Set up the data sources after creating the Purchase Connector instance but before starting to observe transactions:
525+
526+ ``` javascript
527+ // 1. Create the connector
528+ await AppsFlyerPurchaseConnector .create ({
529+ logSubscriptions: true ,
530+ logInApps: true ,
531+ sandbox: __DEV__
532+ });
533+
534+ // 2. Set up data sources
535+ setupPurchaseDataSources ();
536+
537+ // 3. Start observing transactions
538+ await AppsFlyerPurchaseConnector .startObservingTransactions ();
539+ ```
540+
541+ 4 . ** Validation** : The parameters you set will be included in the purchase events sent to AppsFlyer. You can verify this in the AppsFlyer dashboard under the purchase events section.
0 commit comments