1.2.0 • Published 9 months ago

@rollershop/capacitor-emarsys-sdk v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Capacitor Emarsys SDK

Maintenance npm

This Plugin is used as a wrapper for the Emarsys SDK.

Table of Content

Helpful Links

SDK Versions

  • iOS: 3.2.2
  • Android: Not implemented

Install

npm install @rollershop/capacitor-emarsys-sdk
npx cap sync

Setup

Initialize SDK

The following options are available to initialize the SDK:

PropTypeDescriptionSince
mobileEngageApplicationCodestringEmarsys App code, which is generated when the app is added to the account.1.0.0
merchantIdstringEmarsys Predict Merchant ID (If the Predict feature is enabled on the Emarsys account).1.0.0
consoleLogLevelsConsoleLogLevels[]The default console logging is only showing logs when you call an unallowed method. You are able to modify the allowed loglevels for console logging, by setting it during the setup.1.0.0

Examples

In capacitor.config.json:

{
  "plugins": {
    "Emarsys": {
      "mobileEngageApplicationCode": 'yourApplicationCode',
      "merchantId": 'yourMerchantId',
      "consoleLogLevels": ['info', 'debug', '...']
    }
  }
}

In capacitor.config.ts:

/// <reference types="@capacitor/emarsys" />

import { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  plugins: {
    Emarsys: {
      mobileEngageApplicationCode: 'yourApplicationCode',
      merchantId: 'yourMerchantId',
      consoleLogLevels: ['info', 'debug', '...'],
    },
  },
};

export default config;

iOS

The following changes needs to be done in AppDelegate.swift:

  1. Add import: import RollershopCapacitorEmarsysSdk
  2. Extend the base class:
class AppDelegate: EmarsysDelegate {
...

Rich Push Notifications

Push notification could show media content and action buttons besides the title and body. Push notifications with these types of contents are called Rich Notifications.

Setup:

  1. Add a new Notification Service Extension target to your project
    • Guide
    • Name: NotificationService
    • Language: swift
    • If Xcode ask's you tu change the scheme, deny it
  2. Navigate to your App's main Podfile and add at the bottom of the file:
target "NotificationService" do
  pod 'EmarsysNotificationService'
end
  1. You may need to run pod install after it
  2. Open the NotificationService.swift and replace the content with:
import EmarsysNotificationService

class NotificationService: EMSNotificationService {
}

Android

Android is not supported at the moment...

Flow

You need to call register on every app start! This is required, because it could be that the push token has changed and because of the implemented queue. Stacked Messages are send after the register completes to make sure we receive events that were emitted while the app was killed.

Before the register call the listeners should be added.

Example of a PushService.ts:

import { Emarsys } from '@rollershop/capacitor-emarsys-sdk';

public init() {
  Emarsys.addListener('pushMessageEvent', message => {
    // do something
  });
  // add other listeners
  
  Emarsys.register().then(response => {
    // do something with the token (if required)
  });
}

This init() function needs to be called on every app start. Remember that requestPermissions() also needs to be called (if not granted yet), so call that in a good moment as well.

In-App

Because this Plugin is for Capacitor, Inline In-App Messages can't work.

They work by being loaded into a specific view by an id. Because Capacitor works by only having one view with the webview which contains the sources of the inner "website", there are no views where a Inline In-App message could be load into.

Predict

To use the Predict functionality, you have to setup your merchantId during the initialization of the SDK.

At the current time Predict does not support authenticating users with Open ID Connect, identifying a contact with setAuthenticatedContact will disable the usage of Predict features!

DeepLink

In order to track email link clicks that open the application directly with the Emarsys SDK, read here.

API

checkPermissions()

checkPermissions() => Promise<PermissionStatus>

Check permission to receive push notifications.

Returns: Promise<PermissionStatus>

Since: 1.0.0


requestPermissions()

requestPermissions() => Promise<PermissionStatus>

Request permission to receive push notifications.

Returns: Promise<PermissionStatus>

Since: 1.0.0


register()

register() => Promise<TokenResult>

Register the app to receive push notifications.

This method will resolve with the push token or reject if there was a problem. It does not prompt the user for notification permissions, use requestPermissions() first.

Returns: Promise<TokenResult>

Since: 1.0.0


setContact(...)

setContact(options: SetContactOptions) => Promise<void>

After application setup is finished, you can use this method to identify the user with contactFieldValue.

Without contact identification all tracked events will be linked to an anonymous contact in Mobile Engage and will rely on visitor cookies in case of Predict.

ParamType
optionsSetContactOptions

Since: 1.0.0


setAuthenticatedContact(...)

setAuthenticatedContact(options: SetAuthenticatedContactOptions) => Promise<void>

After the application setup is finished, you can use this method to identify the user with an openIdToken.

Without contact identification all tracked events will be linked to an anonymous contact in Mobile Engage and will rely on visitor cookies in case of Predict.

ParamType
optionsSetAuthenticatedContactOptions

Since: 1.0.0


clearContact()

clearContact() => Promise<void>

When the user signs out, this method should be used.

You only need to call clearContact when you explicitly want to sign out the contact from Emarsys even if the user isn’t logged in into your application.

Since: 1.0.0


getPushToken()

getPushToken() => Promise<TokenResult>

Use this method to get the current push token.

Returns: Promise<TokenResult>

Since: 1.0.0


clearPushToken()

clearPushToken() => Promise<void>

Use this method to remove the push token of the contact.

Since: 1.0.0


pauseInApp()

pauseInApp() => Promise<void>

When a critical activity starts and should not be interrupted by In-App, pause In-App messages.

Since: 1.0.0


isInAppPaused()

isInAppPaused() => Promise<{ isPaused: boolean; }>

Use this method to check if in app messages are paused.

Returns: Promise<{ isPaused: boolean; }>

Since: 1.0.0


resumeInApp()

resumeInApp() => Promise<void>

In order to show In-App messages after being paused, use the resume method.

Since: 1.0.0


trackItem(...)

trackItem(options: { itemId: string; }) => Promise<void>

If an item was viewed use the trackItemView method with an itemId.

ParamType
options{ itemId: string; }

Since: 1.0.0


trackCategory(...)

trackCategory(options: { categoryPath: string; }) => Promise<void>

When the user navigates between the categories you should call trackCategoryView in every navigation. Be aware to send categoryPath in the required format. Please visit Predict's documentation for more information.

ParamType
options{ categoryPath: string; }

Since: 1.0.0


trackSearch(...)

trackSearch(options: { searchTerm: string; }) => Promise<void>

To report search terms entered by the contact use trackSearchTerm method.

ParamType
options{ searchTerm: string; }

Since: 1.0.0


trackTag(...)

trackTag(options: { tag: string; }) => Promise<void>

To report search terms entered by the contact use trackSearchTerm method.

ParamType
options{ tag: string; }

Since: 1.0.0


trackCard(...)

trackCard(options: CardItems) => Promise<void>

When you want to track the cart items in the basket you can call this method with a list of CartItems.

ParamType
optionsCardItems

Since: 1.0.0


trackPurchase(...)

trackPurchase(options: Purchase) => Promise<void>

To report a purchase event you should call this method with the items purchased and with an orderId.

ParamType
optionsPurchase

Since: 1.0.0


recommendProducts(...)

recommendProducts(options: RecommendedProductOptions) => Promise<RecommendedProducts>

With the Emarsys SDK you can ask for product recommendations based on different recommendation logics.

This method is also going to track the value attached to the logic on the backend, so no additional tracking needed when using recommendations!

ParamType
optionsRecommendedProductOptions

Returns: Promise<RecommendedProducts>

Since: 1.0.0


trackRecommendationClick(...)

trackRecommendationClick(product: Product) => Promise<void>

The Emarsys SDK doesn't track automatically recommendationClicks, so you have to call manually trackRecommendationClick when an interaction happens with any of the recommended products.

ParamType
productProduct

Since: 1.0.0


fetchMessages()

fetchMessages() => Promise<any>

In order to receive the messageInbox content, you can use this method.

Returns: Promise<any>

Since: 1.0.0


addTag(...)

addTag(options: InboxTag) => Promise<void>

To label a message with a tag, you can use this method. (for example: "READ", "SEEN" etc)

ParamType
optionsInboxTag

Since: 1.0.0


removeTag(...)

removeTag(options: InboxTag) => Promise<void>

To remove a label from a message, you can use this method.

ParamType
optionsInboxTag

Since: 1.0.0


getApplicationCode()

getApplicationCode() => Promise<ApplicationCode>

Provides what is the actual applicationCode set in the SDK.

Returns: Promise<ApplicationCode>

Since: 1.0.0


setApplicationCode(...)

setApplicationCode(options: ApplicationCode) => Promise<void>

If any error occurs during the change process, the Mobile Engage feature will be turned off.

ParamType
optionsApplicationCode

Since: 1.0.0


getMerchantId()

getMerchantId() => Promise<MerchantId>

Provides what is the actual merchantId set in the SDK.

Returns: Promise<MerchantId>

Since: 1.0.0


setMerchantId(...)

setMerchantId(options: MerchantId) => Promise<void>

Change the actual merchantId that is set in the SDK.

ParamType
optionsMerchantId

Since: 1.0.0


getContactFieldId()

getContactFieldId() => Promise<ContactFieldId>

Provides what is the actual contactFieldId set in the SDK.

Returns: Promise<ContactFieldId>

Since: 1.0.0


getHardwareId()

getHardwareId() => Promise<{ hardwareId: string; }>

Provides what is the actual hardwareId set in the SDK.

Returns: Promise<{ hardwareId: string; }>

Since: 1.0.0


getLanguageCode()

getLanguageCode() => Promise<{ languageCode: string; }>

Provides what is the actual language of the application.

Returns: Promise<{ languageCode: string; }>

Since: 1.0.0


getSdkVersion()

getSdkVersion() => Promise<{ sdkVersion: string; }>

Provides the actual sdkVersion

Returns: Promise<{ sdkVersion: string; }>

Since: 1.0.0


addListener('pushMessageEvent', ...)

addListener(eventName: 'pushMessageEvent', listenerFunc: (event: PushMessageEvent) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Called when a event is received

ParamType
eventName'pushMessageEvent'
listenerFunc(event: PushMessageEvent) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

Since: 1.0.0


addListener('silentPushMessageInformation', ...)

addListener(eventName: 'silentPushMessageInformation', listenerFunc: (information: SilentPushMessageInformation) => void) => Promise<PluginListenerHandle> & PluginListenerHandle

Called when a silent push message is received

ParamType
eventName'silentPushMessageInformation'
listenerFunc(information: SilentPushMessageInformation) => void

Returns: Promise<PluginListenerHandle> & PluginListenerHandle

Since: 1.0.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all native listeners for this plugin.

Since: 1.0.0


Interfaces

PermissionStatus

PropTypeSince
receivePermissionState1.0.0

TokenResult

PropTypeSince
tokenstring1.0.0

SetContactOptions

PropTypeSince
contactFieldValuestring1.0.0

SetAuthenticatedContactOptions

PropTypeSince
openIdTokenstring1.0.0

CardItems

PropType
itemsCardItem[]

CardItem

PropTypeSince
itemIdstring1.0.0
pricenumber1.0.0
quantitynumber1.0.0

Purchase

PropTypeSince
orderIdstring1.0.0

RecommendedProducts

PropTypeSince
productsProduct[]1.0.0

Product

PropTypeSince
productIdstring1.0.0
titlestring1.0.0
linkUrlstring1.0.0
customFields{ key: string: any; }1.0.0
featurestring1.0.0
cohortstring1.0.0
imageUrlstring1.0.0
zoomImageUrlstring1.0.0
categoryPathstring1.0.0
availablenumber1.0.0
productDescriptionstring1.0.0
pricenumber1.0.0
msrpnumber1.0.0
albumstring1.0.0
actorstring1.0.0
artiststring1.0.0
authorstring1.0.0
brandstring1.0.0
yearnumber1.0.0

RecommendedProductOptions

PropTypeDescriptionDefaultSince
logicRecommendedProductLogicThe logic that should be used.1.0.0
filterRecommendedProductFilter[]You can filter product recommendations with the SDK. There are two types of filters: Exclude or Include. In every case there are four types of comparators you can use to compare your chosen field to the value. This is an optional parameter.1.0.0
limitnumberYou can limit the number of recommended products received by defining a limit.51.0.0
availabilityZonestringYou can personalize the recommendation further by setting the availabilityZones parameter of the recommendation, to only recommend the locally available products. This is an optional parameter.1.0.0

RecommendedProductSearchLogic

Based on searchTerm

PropTypeSince
type'search'1.0.0
valuestring1.0.0

RecommendedProductCartLogic

Based on cartItems

PropTypeSince
type'cart'1.0.0
valueCardItem[]1.0.0

RecommendedProductRelatedLogic

Based on itemViewId

PropTypeSince
type'related'1.0.0
valuestring1.0.0

RecommendedProductCategoryLogic

Based on categoryPath

PropTypeSince
type'category'1.0.0
valuestring1.0.0

RecommendedProductAlsoBoughtLogic

Based on itemViewId

PropTypeSince
type'also_bought'1.0.0
valuestring1.0.0

RecommendedProductPopularLogic

Based on categoryPath

PropTypeSince
type'popular'1.0.0
valuestring1.0.0

RecommendedProductPersonalLogic

Based on based on current browsing and activity

Optionally based on the variants

PropTypeSince
type'personal'1.0.0
valuestring[]1.0.0

RecommendedProductHomeLogic

Based on most recent browsing behaviour

Optionally based on the variants

PropTypeSince
type'home'1.0.0
valuestring[]1.0.0

RecommendedProductValueFilter

PropTypeDescriptionSince
filterTypeRecommendedProductFilterType1.0.0
comparatorTypeRecommendedProductValueFilterComparatorTypeisValue: checking if the field is matching the value, hasValue: One of the field values is equal to expectation value (applicable only to fields containing multiple values)1.0.0
fieldstring1.0.0
valuestring1.0.0

RecommendedProductArrayFilter

PropTypeDescriptionSince
filterTypeRecommendedProductFilterType1.0.0
comparatorTypeRecommendedProductArrayFilterComparatorTypeinValues: any of the values has a match with the field, overlapsValues: One or more of the field values are found in expectation values (applicable only to fields containing multiple values)1.0.0
fieldstring1.0.0
valuestring[]1.0.0

InboxTag

PropTypeSince
tagstring1.0.0
messageIdstring1.0.0

ApplicationCode

PropTypeSince
applicationCodestring1.0.0

MerchantId

PropTypeSince
merchantIdstring1.0.0

ContactFieldId

PropTypeSince
contactFieldIdnumber1.0.0

PluginListenerHandle

PropType
remove() => Promise<void>

PushMessageEvent

PropTypeSince
eventNamestring1.0.0
data{ key: string; value: string; }[]1.0.0

SilentPushMessageInformation

PropTypeSince
campaignIdstring1.0.0

Type Aliases

PermissionState

'prompt' | 'prompt-with-rationale' | 'granted' | 'denied'

RecommendedProductLogic

RecommendedProductSearchLogic | RecommendedProductCartLogic | RecommendedProductRelatedLogic | RecommendedProductCategoryLogic | RecommendedProductAlsoBoughtLogic | RecommendedProductPopularLogic | RecommendedProductPersonalLogic | RecommendedProductHomeLogic

RecommendedProductFilter

RecommendedProductValueFilter | RecommendedProductArrayFilter

RecommendedProductFilterType

'include' | 'exclude'

RecommendedProductValueFilterComparatorType

'isValue' | 'hasValue'

RecommendedProductArrayFilterComparatorType

'inValues' | 'overlapsValues'

Changelog

The full Changelog is available here

1.2.1-beta.1

9 months ago

1.2.1-beta.2

9 months ago

1.2.1-beta.3

9 months ago

1.2.1-beta.4

9 months ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

1.0.0-beta.2

2 years ago

1.0.0-beta.3

2 years ago

1.0.0-beta.1

2 years ago