npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clevertap

v1.3.0

Published

CleverTap API library for node

Downloads

16,083

Readme

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',
 INDONESIA: 'aps3',
 MIDDLEEAST: 'mec1'
*/
const clevertap = CleverTap.init(YOUR_CLEVERTAP_ACCOUNT_ID, YOUR_CLEVERTAP_ACCOUNT_PASSCODE, CleverTap.REGIONS.EUROPE);

// the library supports both callbacks and Promises

/* Upload Profile or events */
var data = [
  {
    type: "event",
    identity: "6264372124",
    evtName: "choseNewFavoriteFood",
    evtData: {
      value: "sushi",
    },
  },

  {
    type: "profile",
    identity: "6264372124",
    ts: t,
    profileData: {
      favoriteColor: "green",
      Age: 30,
      Phone: "+14155551234",
      Email: "[email protected]",
    },
  },

  {
    type: "event",
    FBID: "34322423",
    evtName: "Product viewed",
    evtData: {
      "Product name": "Casio Chronograph Watch",
      Category: "Mens Watch",
      Price: 59.99,
      Currency: "USD",
    },
  },

  {
    type: "profile",
    objectId: "-2ce3cca260664f70b82b1c6bb505f462",
    profileData: { favoriteFood: "hot dogs" },
  },

  {
    type: "event",
    objectId: "-2ce3cca260664f70b82b1c6bb505f462",
    evtName: "choseNewFavoriteFood",
    evtData: {},
  },

  {
    type: "event",
    identity: "[email protected]",
    ts: t,
    evtName: "Charged",
    evtData: {
      Amount: 300,
      Currency: "USD",
      "Payment mode": "Credit Card",
      Items: [
        {
          Category: "books",
          "Book name": "The millionaire next door",
          Quantity: 1,
        },
        {
          Category: "books",
          "Book name": "Achieving inner zen",
          Quantity: 4,
        },
      ],
    },
  },
];
// callback style
clevertap.upload(data, { debug: 1, batchSize: 1000 }, (res) => {
  console.log(res);
});
// or if you prefer Promises
clevertap.upload(data, { debug: 1, batchSize: 1000 }).then((res) => {
  console.log(res);
});

/* Get Events data */
var eventsQuery = {
  event_name: "choseNewFavoriteFood",
  props: [{ name: "value", operator: "contains", value: "piz" }],
  from: 20150810,
  to: 20151025,
};
// callback style
clevertap.events(eventsQuery, { debug: 1, batchSize: 6000 }, (res) => {
  console.log(res);
});
// or if you prefer Promises
clevertap.events(eventsQuery, { debug: 1, batchSize: 6000 }).then((res) => {
  console.log(res);
});

/* Get profile info */
//callback style
clevertap.profile(
  { objectId: "-2ce3cca260664f70b82b1c6bb505f462", debug: 1 },
  (res) => {
    console.log(res);
  }
);
// or if you prefer Promises
clevertap
  .profile({ objectId: "-2ce3cca260664f70b82b1c6bb505f462", debug: 1 })
  .then((res) => {
    console.log(res);
  });

var profilesQuery = {
  event_name: "choseNewFavoriteFood",
  props: [{ name: "value", operator: "contains", value: "piz" }],
  from: 20150810,
  to: 20151025,
};
//callback style
clevertap.profiles(profilesQuery, { debug: 1, batchSize: 200 }, (res) => {
  console.log(res);
});
// or if you prefer Promises
clevertap.profiles(profilesQuery, { debug: 1, batchSize: 200 }).then((res) => {
  console.log(res);
});

/* Campaign API's - CREATE, ESTIMATE, LIST, RESULT, STOP, TARGET_ACTIONS */
var estimatePayload = {
  name: "green freedom",
  when: "now",
  where: {
    event_name: "App Launched",
    from: 20160101,
    to: 20160317,
  },
  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",
      },
    },
  },
  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);
  });

var createPayload = {
  name: "green freedom",
  when: "now",
  where: {
    event_name: "App Launched",
    from: 20160101,
    to: 20160317,
  },
  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",
      },
    },
  },
  devices: ["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); });

var listPayload = { from: 20160101, to: 20160317 };
//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);});

var stopPayload = { id: 1458261857 };
//callback style
clevertap.targets(clevertap.TARGET_STOP, stopPayload, { debug: 1 }, (res) => {console.log(res);});
// or if you prefer Promises
clevertap
  .targets(clevertap.TARGET_STOP, stopPayload, { debug: 1 })
  .then((res) => { console.log(res);});

var resultPayload = { id: 1458261857 };
//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);});

/* Report API's */
// Get Message Reports
var getMessageReportspayload = { from: "20171101", to: "20171225" };
clevertap
  .getMessageReports(getMessageReportspayload, { debug: 1 })
  .then((res) => {console.log(res);});

// This endpoint enables you to get a real-time count of active users in the past five minutes in your app
var realTimeCountspayload = { user_type: true };
clevertap.realTimeCounts(realTimeCountspayload, { debug: 1 }).then((res) => {console.log(res);});

// This endpoint is used to retrieve counts for the most and least frequently occurring properties for a particular event in a specified duration
var topPropertyCountspayload = {
  event_name: "Charged",
  from: 20161229,
  to: 20170129,
  groups: {
    foo: {
      property_type: "event_properties",
      name: "Amount",
    },
    bar: {
      property_type: "profile_fields",
      name: "Customer Type",
      top_n: 2,
      order: "asc",
    },
  },
};
clevertap
  .topPropertyCounts(topPropertyCountspayload, { debug: 1 })
  .then((res) => {console.log(res);});

// This endpoint is used to retrieve daily, weekly, and monthly event trends in a specified duration.
var trendspayload = {
  event_name: "Charged",
  from: 20161224,
  to: 20170103,
  unique: false,
  sum_event_prop: "Amount",
  groups: {
    foo: {
      trend_type: "daily",
    },
    bar: {
      trend_type: "weekly",
    },
    foobar: {
      trend_type: "monthly",
    },
  },
};
clevertap.trends(trendspayload, { 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