react-moengage
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

React MoEngage

Latest npm version Downloads

A convenient wrapper around the MoEngage Web SDK for React.

Install

npm install --save react-moengage

Usage

import MoEngage from "react-moengage"

MoEngage.init("MOENGAGE_APP_ID", {
    debugLogs: 0,
    swPath: "/customSw.js",
})

MoEngage.trackEvent("PurchaseMade", { ...data })

Methods

All methods are camel-cased versions of those specified in the MoEngage SDK documentation.

MoEngage.trackEvent("PurchaseMade", { value: 0.5 })

MoEngage.addFirstName("Dominick")
MoEngage.addLastName("Cobb")
MoEngage.addEmail("dom@level5.com")
MoEngage.addMobile("+12399999999")

Moengage.addUserAttribute("replenishment_date", new Date(2021, 4, 30))

The moe object is also accessible directly if need-be:

const moe = MoEngage.moe

moe.onsite.registerCallback(...args)
moe.onsite.getData(...args)

Environment

By default debugLogs is set to 1 (test mode).

As in the MoEngage SDK documentation, set debugLogs to 0 in order to push data to your LIVE environment. Set it to 1 in order to push data to your TEST environment & enable logging to the console.

Server-Side Rendering

Please note in order to initialise this library, the MoEngage SDK relies on the window object and therefore will only work in the browser. If server-side rendering, it is recommended to call init() in somewhere like componentDidMount() or useEffect(..., []).

import MoEngage from "react-moengage"

class MyComponent extends React.Component {
    componentDidMount() {
        const options = { ... }
        MoEngage.init("MOENGAGE_APP_ID", options)
    }
}

Package Sidebar

Install

npm i react-moengage

Weekly Downloads

77

Version

1.1.0

License

MIT

Unpacked Size

10.2 kB

Total Files

8

Last publish

Collaborators

  • muntasirsyed