Coder Social home page Coder Social logo

react-moengage's Introduction

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("[email protected]")
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)
    }
}

react-moengage's People

Contributors

dependabot[bot] avatar muntasirsyed avatar

Stargazers

 avatar

Watchers

 avatar  avatar

react-moengage's Issues

Could not find a declaration file for module

Could not find a declaration file for module 'react-moengage'. '/Users/Projects/React-Web/node_modules/react-moengage/dist/react-moengage.js' implicitly has an 'any' type.
Try npm i --save-dev @types/react-moengage if it exists or add a new declaration (.d.ts) file containing declare module 'react-moengage';ts(7016)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.