MoonMail JS Overview
Our JavaScript SDK makes it easy to bring data from your app or website into MoonMail, add new or update existing contacts, trigger event-based campaigns, and more.
Get your account ID
If you don't have a MoonMail account already, you’ll need to create one in order to use the SDK. Navigate to the general settings of your account and copy the Account ID
Setup moonmail.js
You need to include moonmail.js
on your website page by either adding the script tag to the head
of your HTML file, or importing it from the moonmail-js-sdk
module:
- HTML
- ES Module
Initialize
You can provide a default contact information. This contact information will be used in subsequent calls.
- JavaScript
- ES Next
Create or update contact
You can add new contact or updates existing with a given address. Pass additional attributes and metrics to provide useful information that can be used for segmentation.
Note that this code will update default contact.
note
Contact metric values must be a Number
type such as a float or integer. Contact attribute values must have the type String
or be an array of strings.
In your MoonMail dashboard you can create a dynamic segment to target specific contacts, for example a segment that filters all contacts where hobbies
attribute includes hiking
.
Trigger event
You can trigger custom events from you app that can be used to activate an event-based campaign.
You can also pass additional event attributes and metrics to further specify when event-based campaign is triggered.
For example in this case you can create an event-based campaign that is triggered only if event has a metric amount > 1000
.
note
Event metric values must be a Number
type such as a float or integer. Event attribute values must have the type String
or be an array of strings.
You can also pass additional contact information as a second parameter
To trigger multiple events at once pass them as an array
Or with additional event attributes and metrics
Changing default contact
When you initialize MoonMail SDK you can provide a default contact as a second attribute. This contact information will be used in subsequent calls. In order to change the default contact, you can call configure
method. Pass the same parameters to configure
method as when you initialize MoonMail SDK.