Airship

Events

The following events will be sent. You can set the event name of your choice in the console.

Event

Description

PURCHASE_VALIDATED

Sent when the user purchased a product wether it is the start of a trial or a regular purchase of a consumable product.

RENEWAL_DISABLED

Sent when the user deactivates the renewal of a subscription wether it is in trial period or not.

RENEWAL_ENABLED

Sent when the user reactivates

SUBSCRIPTION_EXPIRED

Sent when the subscription actually ends

SUBSCRIPTION_RENEWED

Sent when a subscription renews

TRIAL_STARTED

Sent when a trial starts

TRIAL_CONVERTED

Sent when a user converts from a free trial to a normal paid-period

TRIAL_NOT_CONVERTED

Sent when a user finishes it's trial period without renewing to a paid-period

Associate your users

Naming your users allows our servers to send purchase events on your behalf to Airship. You've got 2 ways of doing it...

  1. From within the app

  2. From your server

From within your app

In the Airship console, enable or disable Named Users in "Settings" APIs & Integrations » Named Users".

In your app, when a user sign-in, associate their id in Airship:

UAirship.namedUser().identifier = "theUserId"

More informations on "named users" can be found here: https://support.airship.com/hc/en-us/articles/360012434371-Step-7-Named-User

From your server

By restricting association to server-side calls only, you have the added security of requiring your master secret to be verified after each call. While increasing security, you also lose the convenience of having your application automatically associate named users on login. Most apps do not require this additional security. But, if your app deals with extremely sensitive data, you may want to leave this setting disabled and associate named users exclusively through the API.

Use the Airship API to associate your users: https://docs.airship.com/api/ua/#operation-api-named_users-associate-post.

require 'urbanairship'

UA = Urbanairship
airship = UA::Client.new(key: '<app key>', secret: '<master secret>')

named_user = UA::NamedUser.new(client: airship)
named_user.named_user_id = 'user-id-1234'
named_user.associate(
    channel_id: 'df6a6b50-9843-0304-d5a5-743f246a4946',
    device_type: 'ios'
  )

Handle anonymous users

If you have anonymous users in your app, we'll need the Airship channel to send purchase events to Airship on your behalf.

if let channelId = UAirship.channel()?.identifier {
	Purchasely.setAttribute(.airshipChannelId, value: channelId)
}

Configure the integration in the Purchasely Console

Go in the "External integrations" section, and open the edition form for Airship:

You'll find your "Airship API key" in your Airship console, section "Settings » APIs & Integrations":

You need to generate the "Airship API token" in your Airship console, section "Settings » APIs & Integrations » Tokens", with the "Audience Modification" role:

Finally, the "Server" to use depends on your app.

  • If your Airship console is on the "go.airship.com" domain, then you'll need to choose the "go.urbanairship.com" server.

  • If your Airship console is on the "go.airship.eu" domain, then you'll need to choose the "go.airship.eu" server.

If you want to, you can rename the events sent to Airship:

The overridden name must only contain alphanumeric lowercase characters, underscores and dashes, as specified in the Airship documentation.

Event example

{
  "body": {
    "name": "purchase_validated_server",
    "properties": {
      "application_name": "Purchasely",
      "application_package_id": "com.purchasely",
      "application_platform": "IOS",
      "plan_id": "PURCHASELY_PLUS_MONTHLY",
      "plan_name": "Monthly",
      "plan_store_product_id": "com.purchasely.plus.monthly",
      "plan_type": "RENEWING_SUBSCRIPTION",
      "product_id": "PURCHASELY_PLUS",
      "product_name": "Purchasely +",
      "store": "APPLE_APP_STORE"
    }
  },
  "occurred":"2021-03-24T17:15:01",
  "user":"12345"
}

Create your automation!

And that's all!

From now on, you'll be able to create as many automations as you want based on Purchasely's events with Airship!

Last updated

© Purchasely 2020-2023