Purchasely
2.8
2.8
  • Welcome page
  • General
    • Presentation
  • Quick test
    • Test in 5 minutes
  • Basic configuration
    • Console Configuration
      • Creating a new application
      • Creating your Products
        • App Store
        • Play Store
        • Huawei App Gallery
        • Amazon App Store
        • Products & Plans
      • Design your Paywalls
    • SDK installation
      • iOS SDK
      • Android SDK
      • React Native SDK
      • Cordova SDK
    • SDK configuration
    • Webhook
      • Receiving and understanding messages
      • Managing entitlements
      • Subscription events
      • Events attributes
      • Detailed sequence diagrams
    • Observer mode
  • Dashboards
    • Introduction
    • Live
    • Subscriptions
    • Cohorts
    • Trials
    • Events
  • S2S notifications
    • Server-to-server notifications ?
    • App Store
    • Play Store
    • Huawei App Gallery
    • Amazon App Store
  • Integrations
    • Airship
    • Amplitude
    • Braze
    • Firebase
  • Advanced Features
    • Anonymous user
    • Associating content
    • Customising UI
      • Errors & alerts
      • Controllers (iOS) / Fragments (Android)
    • Deeplinks automations
    • Displaying users subscriptions
    • UI Analytics
    • Localization
    • Non-subscription products
    • Promoting your products
      • Self-promotion
      • Promoting In-App Purchases
    • Purchase interceptor
    • Purchase manually
    • Subscription status
    • Paywall Guidelines
  • Others
    • Frequently Asked Questions
    • Migration guides
      • Migrate to Purchasely
      • SDK
        • v2.1.3
        • v2.2.0
      • Webhooks
        • v3.0
  • TESTING
    • Testing Cycle Durations
Powered by GitBook

© Purchasely 2020-2023

On this page
  • Configure the SDK
  • Sync your purchases (Android only)

Was this helpful?

  1. Basic configuration

Observer mode

Observer mode allows you to use Purchasely alongside your existing in-app subscription flow.

This is a great way to:

  • Test Purchasely without changing your existing flow

  • Receive the Server-to-server notifications to trigger your automations

  • Connect our data with your marketing tools using our automations

  • Analyse your business with our great charts

  • and … smoothly migrate to Purchasely 🙂

Configure the SDK

Please instantiate Purchasely as soon as the app starts so that we can grab the receipts presented on app launch (PSD2, ask-to-buy, …).

import Purchasely

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
	Purchasely.start(withAPIKey: "API_KEY", appUserId: "USER_ID", observerMode: true)
	return true
}
#import <Purchasely/Purchasely-Swift.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
	// Override point for customization after application launch.

		[Purchasely startWithAPIKey:@"API_KEY"
					  appUserId:@"USER_ID"
				   observerMode:true
				  eventDelegate:nil
					 uiDelegate:nil
		 confirmPurchaseHandler:nil
					   logLevel: LogLevelInfo];

	return YES;
}
import io.purchasely.ext.Purchasely

Purchasely.Builder(applicationContext)
    .apiKey("API_KEY")
    .logLevel(LogLevel.DEBUG) // set to warning or error for release
    .userId("USER_ID")
    .eventListener(eventListener)
    .observerMode(true)
    .stores(listOf(GoogleStore(), HuaweiStore()))
    .build()

// When you are ready for Purchasely to initialize,
// you must call start() method that will grab configuration and products
// from the selected stores.
Purchasely.start()
List<Store> stores = new ArrayList();
stores.add(new GoogleStore(), new HuaweiStore());

new Purchasely.Builder(getApplicationContext())
    .apiKey("API_KEY")
    .logLevel(LogLevel.DEBUG) // set to warning or error for release
    .userId("USER_ID")
    .eventListener(this)
    .observerMode(true)
    .stores(stores)
    .build();

// When you are ready for Purchasely to initialize,
// you must call start() method that will grab configuration and products
// from the selected stores.
Purchasely.start();
import Purchasely from 'react-native-purchasely';

Purchasely.startWithAPIKey(
  'API_KEY',
  ['Google'],
  'USER_ID',
  Purchasely.logLevelDebug,
  true
);
Purchasely.startWithAPIKey('API_KEY', ['Google'], "USER_ID", Purchasely.LogLevel.ERROR, true);

If your user change within your app life cycle, please update Purchasely like that:

Purchasely.userLogin(with: "123456789")
[Purchasely userLoginWith:@"123456789"];
Purchasely.userLogin("123456789") { refresh ->
    if (refresh) {
        //you can call your backend to refresh user information
    }
}
Purchasely.userLogin("123456789", refresh -> {
    if(refresh) {
        //you can call your backend to refresh user information
    }
    return null;
});
Purchasely.userLogin('123456789').then((refresh) => {
  if (refresh) {
    //call your backend to refresh user information
  }
});
Purchasely.userLogin("123456789");

When a user logs out perform a:

Purchasely.userLogout()
[Purchasely userLogout];
Purchasely.userLogout()
Purchasely.userLogout();
Purchasely.userLogout();
Purchasely.userLogout();

Purchasely won't consume your purchases or acknowledge purchases made.

On iOS we won't finish the transaction of your consumables that will remain in the queue if you don't do that in your code.

On Android the transactions will be cancelled and refunded after 3 days.

Sync your purchases (Android only)

When a purchase or a restoration is made with your current flow, call the synchronize() method of our SDK to send the receipt to our backend. This allow us to save the receipts on our server to prepare for your migration.

Purchasely.synchronize()
Purchasely.synchronize();
Purchasely.synchronize();
Purchasely.synchronize();

PreviousDetailed sequence diagramsNextIntroduction

Last updated 3 years ago

Was this helpful?