/PushTemplates

A repo for fancy push notification templates using CleverTap

Primary LanguageJavaMIT LicenseMIT

Download

Push Templates by CleverTap

Push Templates SDK helps you engage with your users using fancy push notification templates built specifically to work with CleverTap.

NOTE

This library is in public beta, for any issues, queries and concerns please open a new issue here

Table of contents

Installation

(Back to top)

Out of the box

  1. Add the dependencies to the build.gradle
implementation 'com.clevertap.android:push-templates:0.0.2'
implementation 'com.clevertap.android:clevertap-android-sdk:3.8.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
  1. Add the Service to your AndroidManifest.xml
<service
    android:name="com.clevertap.pushtemplates.PushTemplateMessagingService">
    <intent-filter>
        <action android:name="com.google.firebase.MESSAGING_EVENT"/>
    </intent-filter>
</service>
  1. Add the Receiver to your AndroidManifest.xml
<receiver
    android:name="com.clevertap.pushtemplates.PushTemplateReceiver"
    android:exported="false"
    android:enabled="true">
</receiver>

Custom Handling Push Notifications

  1. Add the dependencies to the build.gradle
implementation 'com.clevertap.android:push-templates:0.0.2'
implementation 'com.clevertap.android:clevertap-android-sdk:3.8.0'
implementation 'com.github.bumptech.glide:glide:4.11.0'
  1. Add the Receiver to your AndroidManifest.xml
<receiver
    android:name="com.clevertap.pushtemplates.PushTemplateReceiver"
    android:exported="false"
    android:enabled="true">
</receiver>
  1. Add the following code in your custom FirebaseMessageService class
public class MyMessagingService extends FirebaseMessagingService {

    Context context;
    CleverTapAPI instance;

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        try{
            context = getApplicationContext();
            if (remoteMessage.getData().size() > 0) {
                Bundle extras = new Bundle();
                for (Map.Entry<String, String> entry : remoteMessage.getData().entrySet()) {
                    extras.putString(entry.getKey(), entry.getValue());
                }

                instance = CleverTapAPI.getDefaultInstance(getApplicationContext());

                boolean processCleverTapPN = Utils.isPNFromCleverTap(extras);

                if(processCleverTapPN){
                    String pt_id = extras.getString(Constants.PT_ID);
                    if(pt_id == null || pt_id.isEmpty()){
                        CleverTapAPI.createNotification(context,extras);
                    }else{
                        TemplateRenderer.setDebugLevel(2); //-1 for OFF, 0, for INFO, 2 for DEBUG, 3 for VERBOSE (errors)
                        TemplateRenderer.createNotification(context,extras);
                    }
                }else{
                    //Other providers
                }
            }
        }catch (Throwable throwable){
            PTLog.verbose("Error parsing FCM payload",throwable);
        }
    }
}

Dashboard Usage

(Back to top)

While creating a Push Notification campaign on CleverTap, just follow the steps below -

  1. On the "WHAT" section pass any values in the "title" and "message" fields (NOTE: These will be ignored)

Basic

  1. Click on "Advanced" and then click on "Add pair" to add the Template Keys

KVs

  1. You can also add the above keys into one JSON object and use the pt_json key to fill in the values

KVs in JSON

  1. Send a test push and schedule!

Template Types

(Back to top)

Basic Template

Basic Template is the basic push notification received on apps.
(Expanded and unexpanded example)

Basic with color

Auto Carousel Template

Auto carousel is an automatic revolving carousel push notification.
(Expanded and unexpanded example)

Auto Carousel

Rating Template

Rating template lets your users give you feedback, this feedback is captures as an event in CleverTap with the rating as the event property so that it can later be actionable.
(Expanded and unexpanded example)

Rating

Product Catalog Template

Product catalog template lets you show case different images of a product (or a product catalog) before the user can decide to click on the "BUY NOW" option which can take them directly to the product via deep links.
(Expanded and unexpanded example)

Product Display

Five Icons Template

Five icons template is a sticky push notification with no text, just 5 icons and a close button which can help your users go directly to the functionality of their choice with a button's click.

Template Keys

(Back to top)

Basic Template

Basic Template Keys Description
pt_id* Value - pt_basic
pt_title* Title
pt_msg* Message
pt_big_img* Image
pt_ico* Large Icon
pt_bg Background Color in HEX
pt_title_clr Title Color in HEX
pt_msg_clr Message Color in HEX
pt_dl1 One Deep Link (minimum)
pt_json Above keys in JSON format

Auto Carousel Template

Auto Carousel Template Keys Description
pt_id* Value - pt_carousel
pt_title* Title
pt_msg* Message
pt_dl1* One Deep Link (minimum)
pt_img1* Image One
pt_img2* Image Two
pt_img3* Image Three
pt_img4 Image Four
pt_img5 Image Five
pt_bg Background Color in HEX
pt_title_clr Title Color in HEX
pt_msg_clr Message Color in HEX
pt_msg_summary Message line when Notification is expanded
pt_json Above keys in JSON format

Rating Template

Rating Template Keys Description
pt_id* Value - pt_rating
pt_title* Title
pt_msg* Message
pt_default_dl* Default Deep Link for Push Notification
pt_dl1* Deep Link for first/all star(s)
pt_dl2 Deep Link for second star
pt_dl3 Deep Link for third star
pt_dl4 Deep Link for fourth star
pt_dl5 Deep Link for fifth star
pt_bg Background Color in HEX
pt_title_clr Title Color in HEX
pt_msg_clr Message Color in HEX
pt_msg_summary Message line when Notification is expanded
pt_json Above keys in JSON format

Product Catalog Template

Product Catalog Template Keys Description
pt_id* Value - pt_product_display
pt_title* Title
pt_msg* Message
pt_img1* Image One
pt_img2* Image Two
pt_img3* Image Three
pt_bt1* Big text for first image
pt_bt2* Big text for second image
pt_bt3* Big text for third image
pt_st1* Small text for first image
pt_st2* Small text for second image
pt_st3* Small text for third image
pt_dl1* Deep Link for first image
pt_dl2* Deep Link for second image
pt_dl3* Deep Link for third image
pt_bg Background Color in HEX
pt_title_clr Title Color in HEX
pt_msg_clr Message Color in HEX
pt_json Above keys in JSON format

Five Icons Template

Five Icons Template Keys Description
pt_id* Value - pt_five_icons
pt_img1* Icon One
pt_img2* Icon Two
pt_img3* Icon Three
pt_img4* Icon Four
pt_img5* Icon Five
pt_dl1* Deep Link for first icon
pt_dl2* Deep Link for second icon
pt_dl3* Deep Link for third icon
pt_dl4* Deep Link for fourth icon
pt_dl5* Deep Link for fifth icon
pt_json Above keys in JSON format

NOTE

  • (*) - Mandatory
  • pt_title and pt_msg in all the templates support HTML elements like bold <b>, italics <i> and underline <u>

Sample App

(Back to top)

Check out the Sample app

Contributing

(Back to top)

Your contributions are always welcome! Please have a look at the contribution guidelines first. 🎉

License

(Back to top)

The MIT License (MIT) 2020. Please have a look at the LICENSE.md for more details.