Skip to main content
Skip to navigation

By Custom Attributes

AIAsk AIChatGPTClaude

With custom attributes, you can create audiences to target with unique Offerings based on any dimension that's relevant to your business.

Continue reading to learn:

  1. How to start setting custom attributes
  2. How to create Targeting Rules with custom attributes
  3. How to sync custom attributes to serve fresh paywalls

How to start setting custom attributes​

Custom attributes can be set through the setAttributes() method in our SDKs, or via API. For full implementation details, visit the Attributes page.

How to create Targeting Rules with custom attributes​

Open Targeting in your Project's sidebar, then click New rule. After setting a display name, set Audience source to Custom filters in the Audience section and click Add filter. In the new filter row, open the field dropdown and choose your attribute's key from the Custom attributes section.

The list shows the custom attribute keys already set for customers in this Project. If you're adding a new attribute, set it for at least one customer before building your rule.

Custom Attribute Key

Next, select an operator: is, is not, is any of, is not any of, is empty, or is not empty. Then, select or enter the values to match. For attributes with many distinct values, type the values instead of selecting them from the list. Values only affect which customers match once your app sets them for those customers.

To reuse these filters in other rules or in Experiments, click + Save audience. Saved audiences appear in Customers → Audiences.

How to sync custom attributes to serve fresh paywalls​

By default, we'll sync any attributes that you set during an app session when the app is backgrounded. This works great if you're using the attribute for some future need, but if you're looking to use it to serve a unique paywall via Targeting in that same session this is not sufficient.

Therefore, we recommend using the syncAttributesAndOfferingsIfNeeded() method to ensure set attributes can be used for Targeting in the same session.

The syncAttributesAndOfferingsIfNeeded() method​

You can use the syncAttributesAndOfferingsIfNeeded() method to explicitly sync attributes mid-session, which will automatically refresh the cached Offering as well, ensuring your customer sees the correct paywall based on any newly set custom attributes without needing to wait it to load.

We recommend using that method after you've set the last attribute that may be used for a paywall you intend to display in that session.

For example, if during your onboarding you set two attributes which may both be used in Targeting Rules, such as onboarding_survey_use_case and onboarding_survey_experience_level to track answers to those onboarding survey questions; we recommend calling syncAttributesAndOfferingsIfNeeded() once after both attributes have been set.

Calls to this method have a rate limit of 5 per minute to prevent abuse.

Purchases.shared.syncAttributesAndOfferingsIfNeeded { offerings, error in
// Attributes and offerings are synced
}
Was this page helpful?