Simple Push Notifications

Simple push is served by simple push notifications.

Note: Before you can start using this feature, you must configure push notifications. Click here for details.

If an app was not active (was closed or running in the background) and a campaign comes in, a push notification appears in the notification center. When a user clicks the notification, they are taken to the application and a simple push is presented.

If an app is active, the simple push is presented right away.


If you want to handle notification by your side remember to change issuer field. If issuer is set to “Synerise” it is always handled by SyneriseSDK.

Payload

{
  "data": {
    "issuer": "Synerise",
    "message-type": "static-content",
    "content-type": "simple-push",
    "content": {
      "notification": {
        "title": "Synerise Simple Push title",
        "body": "Synerise Simple Push message",
        "sound": "default",
        "icon": "_your_https_url/marvellous_image.jpg",
        "priority": "HIGH",
        "action": {
          "item": "_your_link/",
          "type": "OPEN_URL"
        }
      },
      "buttons": [
        {
          "identifier": "button_1",
          "action": {
            "item": "_your_link/",
            "type": "OPEN_URL"
          },
          "text": "Button 1"
        },
        {
          "identifier": "button_2",
          "action": {
            "item": "syne://product?sku=el-oven",
            "type": "DEEP_LINKING"
          },
          "text": "Button 2"
        }
      ],
      "campaign": {
        "variant_id": 12345,
        "type": "Mobile push",
        "title": "Mobile push test campaign",
        "hash_id": "1893b5be-79c6-4432-xxxx-81e7bd4ea09d"
      }
    }
  }
}

Action types are: DEEP_LINKING, OPEN_URL, OPEN_APP. Priority types are: NORMAL, HIGH.


Banners are served by silent push notifications.

Note: Before you can start using this feature, you must configure push notifications. Click here for details.

It is not always suitable for you to show banners which may come. The application may be in a state you do not want banner cannot cover the user’s screen.

Fortunately, you can control incoming banners by implementing an optional listener OnBannerListener:

Callback shouldPresent decides whether to show banner if any came. SDK allows to show banner by default. Callback onPresented is fired when banner is successfully created and will be presented to user. Note, that banner will not be presented to user if it’s content is invalid and therefore callback will not be fired. Callback onClosed is fired the very moment before banner is closed.

public static OnBannerListener NULL = new OnBannerListener() {
        @Override
        public boolean shouldPresent(TemplateBanner banner) {
            return true;
        }

        @Override
        public void onPresented() { }

        @Override
        public void onClosed() { }
    };

Payload

{
  "notification": {
    "title": "Notification title if app was invisible",
    "body": "Notification message if app was invisible"
  },
  "data": {
    "issuer": "Synerise",
    "message-type": "dynamic-content",
    "content-type": "template-banner",
    "content": {
      "page": {
        "type": "image_with_text_atop",
        "button": {
          "is_enabled": true,
          "corner_radius": 40,
          "color": "#13e413",
          "text": "Navigate to Synerise",
          "text_color": "#1f74d9"
        },
        "image": {
          "url": "_your_https_url/marvellous_image.jpg"
        },
        "close_button": {
          "is_enabled": true,
          "alignment": "LEFT"
        },
        "background": {
          "color": "#d319d3",
          "alpha": 0.5
        },
        "index": 0,
        "header": {
          "color": "#384350",
          "size": 35,
          "alpha": 1,
          "text": "SYNERISE"
        },
        "description": {
          "color": "#384350",
          "size": 20,
          "alpha": 1,
          "text": "Click below button to open Synerise website"
        },
        "action": {
          "item": "_your_link_",
          "type": "OPEN_URL"
        }
      },
      "auto_disappear": {
        "is_enabled": true,
        "timeout": 5
      },
      "campaign": {
        "variant_id": 12345,
        "type": "Mobile banner",
        "title": "Mobile banner test campaign",
        "hash_id": "1893b5be-79c6-4432-xxxx-81e7bd4ea09d"
      }
    }
  }
}

Banner types are: color_as_background, image_as_background, image_with_text_atop, image_with_text_below.

Remember when app is not running banner will appear as notification which has got firebase notification default icon. (Your app icon as default) If you want to set other icon, do it in android manifest file as shown below:

<meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/your_icon_here" />

Triggers

In order to show a banner immediately after a certain event occurred, you can send your banners from the Synerise panel with a trigger value.

When Injector.fetchBanners(success:failure:) is called, it fetches all available banners, and then SDK caches those that are valid. You receive an array of banners formatted as a dictionary.

This method is also called during SDK initialization, so use it only when you wish to overwrite the current banners in SDK cache.

Injector.getBanners() provides valid banners directly from the SDK cache.

Note: The exact same banners are being searched for eventual campaign triggers.

You can keep banner data from:

  • Injector.fetchBanners(success:failure:) - fetch available banners (SDK will refresh cache).
  • Injector.getBanners() - get available banners from SDK cache.
  • snr_shouldBannerAppear(bannerDictionary: Dictionary) - optional delegate method. See Banner campaign section above for more information.

Next, call Injector.showBanner(_: Dictionary) to show a banner immediately. In this case, the delegate method snr_shouldBannerAppear(bannerDictionary: Dictionary) will not be called.

Note: The banner will appear even if your View Controller implements SyneriseActivityNotAllowed protocol. See common features for more information.

Walkthrough

Synerise SDK provides multiple functionalities within Walkthrough implementation.

First of all, you are able to specify Walkthrough behavior the moment SDK initializes:

Synerise.Builder.with(this, syneriseClientApiKey, appId)
        .notificationIcon(R.drawable.ic_notification_icon)
        .injectorAutomatic(true)
        .build();

Setting .injectorAutomatic(true) will fetch Walkthrough right away. Note, that Walkthrough will be presented the moment it gets loaded atop of your current Activity if it’s id is different than previously presented.

Please note that walkthrough is translucent activity, so your activity’s onStop() method may not be called. Also walkthrough activity is launched with FLAG_ACTIVITY_NEW_TASK flag so you can handle your activity stack properly. To control this behavior please fetch your Walkthrough manually with Injector.getWalkthrough().

This method cancels previous API request (if any) and then starts loading Walkthrough asynchronously. Also, it must be called after Injector.setOnWalkthroughListener(OnWalkthroughListener) to receive callbacks properly. See Optional callbacks section below.

You can check if Walkthrough is already loaded with Injector.isWalkthroughLoaded() method, which returns true if Walkthrough is already loaded.

Moreover, there is an enhanced method to check if Walkthrough is loaded. Injector.isLoadedWalkthroughUnique() verifies whether loaded Walkthrough is different than previously presented. Every time any Walkthrough is presented it’s id is cached locally, therefore you can control your flow more precisely. In summary, method will return true if loaded Walkthrough is different than previously presented, false otherwise or if Walkthrough is not loaded.

Finally, Injector.showWalkthrough() shows Walkthrough if loaded. This method may be called wherever in your application as many times you want. It also returns true if Walkthrough was loaded, false otherwise.

Optional callbacks

When you choose to load and present Walkthrough manually, you may be interested in following callbacks:

Injector.setOnWalkthroughListener(new OnWalkthroughListener() {

            @Override
            public void onLoadingError(ApiError error) {
                error.printStackTrace();
                goDashboard();
            }

            @Override
            public void onLoaded() {
                if (Injector.isLoadedWalkthroughUnique()) {
                    Injector.showWalkthrough();
                } else {
                    goDashboard();
                }
            }

            @Override
            public void onPresented() {
                super.onPresented();
            }

            @Override
            public void onClosed() {
                super.onClosed();
            }
        });

Note, that all these methods are optional and overriding them is not required. These are also called when Walkthrough was loaded automatically.

  1. onLoadingError(ApiError) - This callback is fired the moment after Walkthrough failed to get initialized. This error may be caused by unsuccessful API response or invalid Walkthrough content. ApiError instance is provided to check error cause.
  2. onLoaded() - This callback is fired the moment after Walkthrough is initialized successfully. Remember, that Walkthrough will be showed automatically if Synerise.Builder.injectorAutomatic(boolean) was set to true and if it’s id is different than previously presented.
  3. onPresented() - This callback is fired when Walkthrough is successfully created and will be presented to user. Note, that Walkthrough will not be presented to user if it’s content is invalid and therefore callback will not be fired.
  4. onClosed() - This callback is fired the very moment before Walkthrough is closed.

Please remember to remove Walkthrough listener to stop receiving callbacks:

Injector.removeWalkthroughListener();

Common features

Handling app invisibility

If app was invisible to user (minimized or destroyed) and campaign banner came in - simple push message is presented to the user and launcher activity is fired after notification click.
It is a prefect moment for you to pass this data and SDK will verify whether it is campaign banner and if so, banner will be presented within the app (atop of your activities). Please note that banner is a translucent activity, so your activity’s onStop() method may not be called. Also banner activity is launched with FLAG_ACTIVITY_NEW_TASK flag so you can handle your activity stack properly.
If your launcher activity last quite longer, check onNewIntent(Intent) implementation below.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        boolean isSynerisePush = Injector.handlePushPayload(getIntent().getExtras());
    }

Note that method Injector.handlePushPayload(getIntent().getExtras()); must be called to handle notification by SyneriseSdk.

When it seems like your launcher activity is not necessarily a short splash or it just simply takes some time before moving on, you might be interested in onNewIntent(Intent) method. In this case it is preferred to override this method. The reason is very simple - when campaign banner came while app was minimized, simple push is presented to the user in the system tray. If your launcher activity was already created and notification was clicked - your onCreate(Bundle) method will not be called.

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);

        boolean isSynerisePush = Injector.handlePushPayload(intent.getExtras());
    }

Own implementation (Simple Push, Banner)

You can also react to Synerise push notifications by yourself and that is why we would like to share our Synerise Simple Push and Synerise Banner payload (see corresponding sections above).

Sometimes you may need to know whether incoming push message comes from Synerise and if so, what information is exactly carrying.

Injector.isSynerisePush(Map<String, String>) only checks whether provided push data comes from Synerise. It is validated by checking if incoming push contains “issuer” key with “Synerise” value.

Injector.isSyneriseSimplePush(Map<String, String>) only checks whether provided push data comes from Synerise and is it specifically Synerise Simple Push. It is validated by checking if incoming push contains “content-type” key with “simple-push” value.

Injector.isSyneriseBanner(Map<String, String>) only checks whether provided push data comes from Synerise and is it specifically Synerise Banner. It is validated by checking if incoming push contains “content-type” key with “template-banner” value.

Injector.isSilentCommand only checks whether provided push data comes from Synerise and is it specifically Silent Command. It is validated by checking if incoming push contains “content-type” key with “silent-command” value.

Injector.isSilentSdkCommand only checks whether provided push data comes from Synerise and is it specifically Silent SDK Command. It is validated by checking if incoming push contains “content-type” key with “silent-sdk-command” value.

Campaign Pushes information

Injector.getPushes() gets all available simple and silent pushes for this client. IDataApiCall with parametrized list of SynerisePushResponse is returned to execute request.

😕

We are sorry to hear that

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.

😉

Awesome!

Thank you for helping improve out documentation. If you need help or have any questions, please consider contacting support.