Cordova AGC App Messaging: Sample Cordova Project
Hi everyone, this article provides usage of AppGallery Connect App Messaging for Cordova mobile application. First of all, I would like to talk about the possibilities that AGC App Messaging provides.
About AGC App Messaging
You can use App Messaging of AppGallery Connect to send relevant messages to target users actively using your app to encourage them to use key app functions, or send attractive promotion activities to enhance user loyalty. App Messaging even allows you to customize how your messages look and the way they will be sent, in addition to default message layouts. You can also define events for triggering message sending to your users at the right moment.
How to the App Messaging Service Works
After you integrate the Cordova AGC App Messaging plugin into your app, the plugin automatically synchronizes in-app messages published on the AppGallery Connect server and determines whether to display a specific in-app message once it is triggered by an in-app event, through a layout.
Integrating AGC Cloud Functions Plugin
Creating and Adding an AppGallery Connect Project
A project is a container of your apps in AppGallery Connect. You can add different platform versions of an app to the same project. Before creating an app, create a project in AppGallery Connect first.
1. Sign in to AppGallery Connect and select My projects.
2. Click Add project.
3. Enter a project name and click OK.
4. After the project is created, the Project settings page is displayed. You need to add an app to the project.
5. Go to Project settings > General information, and click Add app.
6. On the Add app page, enter app information.
7. On the Project settings page, download the configuration file agconnect-services.json and agconnect-services.plist.
8. Package name set in config.xml file.
Cordova Sample Project Using Cordova AGC App Messaging Plugin
- Download the Cordova sample project from the link.
Project contains the Cordova client sample code for testing App Messaging.
- Download the Cordova AGC Cloud Functios Plugin from the link.
Creating an In-App Message
To send in-app messages to users in specific scenarios, you need to create them in AppGallery Connect first and set the message layout and sending target.
- Sign in to AppGallery Connect and click My projects.
- Click your project from the project list.
- Go to Grow > App Messaging and click New.
4. Set Name and Description.
5. Set the layout and content and click Next.
Select the message type from the Type drop-down list box. Currently, the following options are supported: Modal, Image, and Banner.
6. Set the target users and click Next.
7. Set the sending time and click Next.
8. Click Publish in the upper right corner to complete message release.
Using Cordova CLI
- Add android platform to the project with using Cordova CLI.
- Add iOS platform to the project with using Cordova CLI.
- Integrate Cordova AGC Cloud Functions Plugin to your project with using Cordova CLI.
- Copy agconnect-services.json file to <project_root>/platforms/android/app directory your Android project.
- Add agconnect-services.plist file to the app’s root directory of your Xcode project.
- Run the Android application
- Run the iOS application
Set Display Enable or Disable
The Cordova App Messaging plugin allows you to enable or disable the message display function. The function is enabled by default.
Changing the Location of Message Layout
If you want to change the location of the message layout, you can use the AGCAppMessaging.setDisplayLocation method.
Interaction and Response
To add a listener, use the AGCAppMessaging.addListener method. You should pass an Events enum value and a callback method that is called when the event is triggered.
In this article, I explained what is the Cordova AGC App Messaging plugin, what capabilities it provides, and how to use it in the Cordova mobile application. If you have any questions, you can write the question in the comment section.