Coder Social home page Coder Social logo

clevertap-node's Introduction

clevertap-node

npm version

CI Status

Fully async Node.js server module for accessing the CleverTap Server API

Install

npm install clevertap

Usage

// require the library
const CleverTap = require('clevertap');
/**
 init the library with your CleverTap Account Id, CleverTap Account Passcode and CleverTap Account Region
 Clevertap Account Regions:
 EUROPE: 'eu1', // default for most accounts
 INDIA: 'in1',
 SINGAPORE: 'sg1',
 US: 'us1'
*/
const clevertap = CleverTap.init(YOUR_CLEVERTAP_ACCOUNT_ID, YOUR_CLEVERTAP_ACCOUNT_PASSCODE, CleverTap.CLEVERTAP_REGIONS.EUROPE);

// the library supports both callbacks and Promises

// upload an array of event/profile records callback style
clevertap.upload(data, {"debug":1, batchSize:50}, (res) => {console.log(res)});

// or if you prefer Promises
clevertap.upload(data, {"debug":1, batchSize:50}).then( (res) => {console.log(res)} );

// query for events
var query = {"event_name":"choseNewFavoriteFood",
                "props":
                [{"name":"value","operator":"contains", "value":"piz"}],
                "from": 20210101,
                "to": 20210701
            };

//callback style
clevertap.events(query, {debug:1, batchSize:500}, (res) => {console.log(res)});

// or if you prefer Promises
clevertap.events(query, {debug:1, batchSize:500}).then( (res) => {console.log(res)} );

//query for user profiles
var query = {"event_name":"choseNewFavoriteFood",
              "from": 20210101,
              "to": 20210701
            }

//callback style
clevertap.profiles(query, {debug:1, batchSize:200}, (res) => {console.log(res)});

// or if you prefer Promises
clevertap.profiles(query, {debug:1, batchSize:200}).then( (res) => {console.log(res)} );

// send a push notification
var createPayload = {
        "name": "green freedom",
        "when": "now",
        "where": {
            "event_name": "App Launched",
            "from": 20210101,
            "to": 20210701,
            },
        "content":{
            "title":"Hello!",
            "body":"Strictly Green Lantern fans only!",
            "platform_specific": {
                "ios": {
                    "deep_link": "judepereira.com",
                    "sound_file": "judepereira.wav",
                    "category": "reactive",
                    "badge_count": 1,
                    "foo": "bar_ios"
                    },
                "android": {
                    "background_image": "http://judepereira.com/a.jpg",
                    "default_sound": true,
                    "deep_link": "judepereira.com",
                    "foo": "bar_android",
                    "wzrk_cid":"BRTesting"
                    }
                }
            },
        "devices": [
            "android",
            "ios"
            ],
        }

//callback style
clevertap.targets(clevertap.TARGET_CREATE, createPayload, {"debug":1}, (res) => {console.log(res)} );

// or if you prefer Promises
clevertap.targets(clevertap.TARGET_CREATE, createPayload, {"debug":1}).then( (res) => {console.log(res)} );

//Estimate a target compaigns
var estimatePayload = {
    "name": "green freedom",
    "when": "now",
    //This flag should be add in the the payload for target estimate api
    "estimate_only": true,
    "where": {
        "event_name": "App Launched",
        "from": 20210101,
        "to": 20210701,
    },
    "content":{
        "title":"Hello!",
        "body":"Strictly Green Lantern fans only!",
        "platform_specific": {
            "ios": {
                "deep_link": "judepereira.com",
                "sound_file": "judepereira.wav",
                "category": "reactive",
                "badge_count": 1,
                "foo": "bar_ios"
            },
            "android": {
                "background_image": "http://judepereira.com/a.jpg",
                "default_sound": true,
                "deep_link": "judepereira.com",
                "foo": "bar_android",
                "wzrk_cid":"BRTesting"
            }
        }
    },
    "devices": [
        "android",
        "ios"
    ],
}
//callback style
clevertap.targets(clevertap.TARGET_ESTIMATE, estimatePayload, {"debug":1}, (res) => {console.log(res)} );

// or if you prefer Promises
clevertap.targets(clevertap.TARGET_ESTIMATE, estimatePayload, {"debug":1}).then( (res) => {console.log(res)} );

//List all target compaigns in a date range
var listPayload = {"from": 20210101, "to": 20210701}
//callback style
clevertap.targets(clevertap.TARGET_LIST, listPayload, {"debug":1}, (res) => {console.log(res)} );

// or if you prefer Promises
clevertap.targets(clevertap.TARGET_LIST, listPayload, {"debug":1}).then( (res) => {console.log(res)} );

//Stop a specific target compaign
var stopPayload = {"id": 1629904249}
//callback style
clevertap.targets(clevertap.TARGET_STOP, stopPayload, {"debug":1}, (res) => {console.log(res)} );

// or if you prefer Promises
clevertap.targets(clevertap.TARGET_STOP, createPayload, {"debug":1}).then( (res) => {console.log(res)} );

//Resule out  a target compaign
var resultPayload = {"id": 1629904249}
//callback style
clevertap.targets(clevertap.TARGET_RESULT, resultPayload, {"debug":1}, (res) => {console.log(res)} );

// or if you prefer Promises
clevertap.targets(clevertap.TARGET_RESULT, resultPayload, {"debug":1}).then( (res) => {console.log(res)} );

See example.js for more detailed usage.

Also please see our Server API documentation.

Tests

npm install  
npm test // all tests 
npm run testpush // just push specific tests

clevertap-node's People

Contributors

abhishek-g-clevertap avatar prashantpandey10 avatar pwilkniss avatar

Watchers

 avatar  avatar

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.