CleverPush Developer Docs

CleverPush Developer Docs

  • SDK Docs
  • API Overview
  • API Reference

›Capacitor SDK

JavaScript SDK

  • Setup
  • Methods

iOS SDK

  • Setup
  • Methods
  • Inbox View
  • Chat
  • Stories
  • Deep Links
  • Live Activities
  • Troubleshooting
  • Changelog

Android SDK

  • Setup
  • Methods
  • Notification Extender Service
  • Inbox View
  • Chat
  • Stories
  • Deep Links
  • Troubleshooting
  • Upgrading
  • Changelog

Capacitor SDK

  • Setup
  • Methods
  • Changelog

Cordova SDK

  • Setup
  • Methods
  • Changelog

React Native SDK

  • Setup
  • Methods
  • Changelog

Xamarin SDK

  • Setup
  • Methods
  • Changelog

Flutter SDK

  • Setup
  • Methods
  • Chat
  • Troubleshooting
  • Changelog

Methods

Initialization

Add the initialization code like this:

import CleverPush from 'cleverpush-capacitor-sdk';

const Home: React.FC = () => {
  useEffect(() => {
    const subscribedListener = ({ subscriptionId }) => {
      console.log('CleverPush subscriptionId:', subscriptionId);
    };

    const notificationReceivedListener = ({ notification }) => {
      console.log('CleverPush notification received:', JSON.stringify(notification));
    };

    const notificationOpenedListener = ({ notification }) => {
      console.log('CleverPush notification opened:', JSON.stringify(notification));
    };

    CleverPush.addListener('subscribed', subscribedListener);
    CleverPush.addListener('notificationReceived', notificationReceivedListener);
    CleverPush.addListener('notificationOpened', notificationOpenedListener);

    // set this to `false` to prevent the SDK from automatically subscribing the user on the first launch of the SDK
    const autoRegister = true;

    // You can get the Channel ID from your CleverPush channel settings
    CleverPush.init({
      channelId: "INSERT_YOUR_CHANNEL_ID",
      autoRegister: autoRegister
    });
  }, []);
};

Basic usage

Subscribe:

CleverPush.subscribe().then(({ subscriptionId }) => {

});

Unsubscribe:

CleverPush.unsubscribe();

Check if subscribed:

CleverPush.isSubscribed().then(({ isSubscribed }) => {
  
});

Get Subscription ID (after subscribe)

CleverPush.getSubscriptionId().then(({ subscriptionId }) => {
  
});

App Banners

This listener will be called when a button in an app banner is clicked.

const appBannerOpenedListener = (subscriptionId) => {
  console.log('CleverPush subscriptionId:', subscriptionId);
};

CleverPush.addListener('appBannerOpened', appBannerOpenedListener);

Automatic Tag Assignment

The SDK can also automatically assign tags by using the trackPageView method. In simple cases you can just give the method a URL. In the CleverPush backoffice you can then set trigger the tags by matching URL Pathname RegExes. You can optionally also set combinations of min. visits, seconds or sessions for this tag.

Let's say you have created a tag with the URL pathname regex "/sports". This would trigger the tag for a subscriber:

JavaScript
CleverPush.trackPageView({ url: "https://..." })

Tags

JavaScript
// add subscription tag
CleverPush.addSubscriptionTag({ tagId: "" })
// remove subscription tag
CleverPush.removeSubscriptionTag({ tagId: "" })
// check subscription tag exists or not
const hasTag = await CleverPush.hasSubscriptionTag({ tagId: "" })
// get subscription tags
const tags = CleverPush.getSubscriptionTags()

Topics

JavaScript
// set setSubscription topics
CleverPush.setSubscriptionTopics({ topics: ["", ""] })
// get subscription topics
const topics = await CleverPush.getSubscriptionTopics()
// get available topics
const availableTopics = await CleverPush.getAvailableTopics()

Get received notifications:

JavaScript
const { notifications } = await CleverPush.getNotifications();
← SetupChangelog →
  • Initialization
  • Basic usage
  • App Banners
  • Automatic Tag Assignment
  • Tags
  • Topics
  • Get received notifications:
SDKs
JavaScriptiOSAndroidCordovaCapacitorReact NativeXamarinFlutter
Community
TwitterFacebookGitHub
More
API ReferenceAPI OverviewBlogImprintPrivacy PolicyTerms of serviceGDPR
Copyright © 2023 CleverPush