LogoLogo
  • Home
  • Integration & SDKs
    • Web / Browser Push
      • Wordpress Integration Steps
      • Wix Integration Steps
      • Safari
        • Safari on Desktop
        • Safari on Mobile (iOS / iPadOS)
      • SDK
        • SDK Methods
        • SDK Events
        • Customizing Prompt CSS
        • AMP Support
        • E-Commerce / Abandoned Cart
    • Native App Push
      • Apple / iOS
        • P8 Key or P12 Cert Setup
        • SDK: Swift / Obj-C
          • Activity Tracking
          • Deep Linking
          • Live Activities
          • App Messages
          • Identity Synchronization
          • SDK Methods
          • SDK Delegates
        • SDK: React Native
        • SDK: Flutter
        • Advanced
          • Self-Managed Integration
        • iOS SDK Changelog
      • Android
        • Firebase App Setup
        • SDK: Kotlin / Java
          • Deep Linking
          • Activity Tracking
          • App Messages
          • Identity Synchronization
          • SDK Methods
          • SDK Callbacks
          • Live Activities
        • SDK: React Native
        • SDK: Flutter
        • Advanced
          • Self-Managed Integration
        • Android SDK Changelog
      • React Native
        • Android: Firebase App Setup
        • iOS: P8 Key or P12 Cert Setup
        • SDK: React Native
          • Deep Linking
          • Activity Tracking
          • Subscriber Matching
          • Live Activities
          • App Messages
          • SDK Methods
        • React Native SDK Changelog
      • Flutter
        • Android: Firebase App Setup
        • iOS: P8 Key or P12 Cert Setup
        • SDK: Flutter
          • Deep Linking
          • Activity Tracking
          • Subscriber Matching
          • Live Activities
          • App Messages
          • SDK Methods
  • API
    • API Access Management
    • API Reference
  • Platform
    • Dashboard
    • Notifications
      • A/B Testing
      • Custom Buttons
      • Notification Previews
      • Inline Segmentation
      • Notification Templates
      • Macros
      • Native App Push Notifications
    • App Messages
    • Segments
      • Custom Geo Segmentation
    • Campaigns
    • Insights
    • User Management
    • Organizations
      • Multi-Factor Authentication
      • Single Sign On
        • Google Workspace
        • Microsoft Azure AD
        • Okta Workforce
      • Multi-Domain Notifications
      • Multi-Domain Segments
      • API Access
    • Multi-Channel Notifications
  • Info Center
    • Launch Guide & Best Practices
      • Landing Domain Whitelist
    • Web / Browser Push
      • Common Questions
      • Browser Support
      • Retrieve Push User ID
      • Not Getting Prompted
      • Not Receiving Notifications
      • How to Unsubscribe
    • Native App Push
      • Retrieve Push User ID
    • Workflow Planning
Powered by GitBook
On this page
  • Manually Triggering the Opt-In Prompt
  • Adding Attributes to a Subscriber's Profile
  • Adding Page Keywords / Tags to a Subscriber's Profile
  • Retrieving the Subscriber's User ID
  • Setting the Subscriber's External ID
  • Removing a Subscriber's External ID
  • Determining if a Visitor is Already Subscribed
  • Determining if a Visitor is Eligible to Prompt
  • Pausing / Resuming a User's Notifications (Soft Unsubscribe)
  • Permanently Delete a User
  1. Integration & SDKs
  2. Web / Browser Push
  3. SDK

SDK Methods

Manually Triggering the Opt-In Prompt

You may choose to disable automatic triggering of the opt-in prompt via the platform. In this scenario you would choose to trigger the prompt based on your own criteria (eg: after a visitor clicks a specific link, visits a specific page, etc).

Triggering the prompt is as easy as calling the show_prompt event when a visitor performs the desired action.

pushly('show_prompt', { checkEligibility: true })

If you want the prompt to show regardless of current subscription status or frequency capping (i.e., manually displaying a bell or custom prompt) this can be simplified to the following code.

pushly('show_prompt')

Adding Attributes to a Subscriber's Profile

You can add attributes to a subscriber's profile and later perform segmentation based on those attributes. For example, you may want to tag visitors who are interested in a specific type of news (eg: politics, sports) so that you can target them with specific notifications.

pushly('profile', {
  'is_paying_subscriber': true,
  'interests': ['poltics', 'news']
});

Property values can be scalar or an array of scalar values.

If you're storing the value of a property as an array you can use the profile_append and profile_remove methods to add or remove values.

// add 'sports' to the subscriber's interests
pushly('profile_append', {
  'interests': ['sports']
});

// remove 'fashion' and 'news' from the subscriber's interests
pushly('profile_remove', {
  'interests': ['fashion', 'news']
});

Properties using profile_append will only store the most recent 20 values provided.

Adding Page Keywords / Tags to a Subscriber's Profile

You can add page keywords / tags to a subscribers profile for every page they visit. These tags can then be used in segmentation to create cohorts of subscribers that have visited tags based on number of times and recency. For example: "Subscribers who have visited a page tagged with "Astrology" at least 4 times in the last 30 days".

pushly('page_tag_visit', ['Tag1', 'Tag2', 'Tag3']);

Retrieving the Subscriber's User ID

Run the following code to the get the user's Pushly ID. This is a transient ID that may change often so it should not be used for long-term visitor identification.

pushly('on_ready', function() {
    PushlySDK.getUser().getId();
});

Setting the Subscriber's External ID

Providing a unique User ID for your subscriber allows you to later interact with that subscriber via the API.

There are two ways to provide the external ID:

On SDK Init

Preferably you may provide the external ID when the SDK is initialized. This requires adding one additional line of code to the load function. Note the new externalId line in the below script:

<script src="https://cdn.p-n.io/pushly-sdk.min.js?domain_key=DOMAIN_KEY" async></script>
<script>
  var PushlySDK = window.PushlySDK || [];
  function pushly() { PushlySDK.push(arguments) }
  pushly('load', {
    domainKey: 'DOMAIN_KEY',
    externalId: 'REPLACE_WITH_USER_ID'
  });
</script>

Via a separate method call

Alternatively you may provide the external ID any time after the SDK has loaded via the following code:

pushly('external_id', 'h7bwKwuE3');

Once a subscriber's external ID has been set you may work with our team to set up bi-directional automated data syncs. The following use cases are common ways that publishers use the external ID via server-to-server requests:

  • Sending notifications to individual subscribers programmatically

  • Processing unsubscribe requests

  • Adding and removing profile attributes and events to subscribers

Removing a Subscriber's External ID

If you want to disassociate an External ID from a subscriber run the following javascript:

pushly('deregister_external_id');

Determining if a Visitor is Already Subscribed

If you need to know if a visitor is already subscribed to push notifications the following javascript can be used:

pushly('on_ready', function() {
    await PushlySDK.isUserSubscribed();
});

The result of this call will be a boolean true or false representing the subscription status of the visitor.

Determining if a Visitor is Eligible to Prompt

If you need to determine if the visitor meets all requirements to be prompted for push permission run the following JavaScript:

pushly('on_ready', function() {
    await PushlySDK.isUserEligibleToPrompt();
});

The result of this call will be a boolean true or false representing if the visitor is eligible to be shown a permission dialog.

Pausing / Resuming a User's Notifications (Soft Unsubscribe)

A user's notifications can be paused by calling the following method:

pushly('pause_notifications')

If the user's notifications should be resumed call the following method:

pushly('resume_notifications')

To check if the user's notifications are currently paused:

pushly('get_notifications_paused_state', (isPaused) => { ... })

Permanently Delete a User

If the user should be excluded from all notifications and tracking run the following method:

pushly('request_user_deletion');

This method works only as a soft unsubscribe. If the subscriber clears their cookies they may get re-opted into notifications.

PreviousSDKNextSDK Events

Last updated 1 month ago

This method is only available after the SDK is fully loaded. This SDK method should be wrapped inside of the on_ready .

This method is only available after the SDK is fully loaded. This SDK method should be wrapped inside of the on_ready .

Note the use of the event to ensure that the SDK is ready for interaction.

This method is only available after the SDK is fully loaded. This SDK method should be wrapped inside of the on_ready .

Note the use of the event to ensure that the SDK is ready for interaction.

event
event
event
on_ready
on_ready