Skip to content

netreconlab/parse-server-any-analytics-adapter

Repository files navigation

parse-server-any-analytics-adapter

npm version ci release codecov vulnerabilities dependency up-to-date weekly downloads License

This library allow a Parse Server to leverage the Analytics library to connect to any 3rd party analytics tool 💹.

Table of Contents

Installation

This module is distributed via npm:

npm install parse-server-any-analytics-adapter --save

Usage

Server

const { AnyAnalyticsAdapter } = require('parse-server-any-analytics-adapter');
const { init: googleAnalytics } = require('@analytics/google-analytics');
const { init: customerIo } = require('@analytics/customerio');

/* Initialize AnyAnalytics with with any and all 3rd party analytics of your choosing. */
const anyAnalytics = new AnyAnalyticsAdapter({
  app: 'my-app-name', /* Name of site / app */
  version: 100, /* Version of your app */
  plugins: [ /* Array of analytics plugins */
    googleAnalytics({
      trackingId: 'UA-121991291',
    }),
    customerIo({
      siteId: '123-xyz'
    })
  ]
});

/* Initialize parse server */
const api = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/dev',
  cloud: __dirname + '/cloud/main.js',
  appId: 'myAppId',
  masterKey: 'myKey',
  ...,
  analyticsAdapter: anyAnalytics, /* Place your instance of AnyAnalytics here. */
  ...
});

/* Finish mounting your Parse Server */
...

Client

You can use REST or any Parse SDK that has the ability to send Parse Analytics such as the Parse-Swift SDK:

//: To track when the app has been opened, do the following.
ParseAnalytics.trackAppOpened { result in
    switch result {
    case .success:
        print("Saved analytics for app opened.")
    case .failure(let error):
        print(error)
    }
}

//: To track any event, do the following.
var friendEvent = ParseAnalytics(name: "openedFriendList")
friendEvent.track { result in
    switch result {
    case .success:
        print("Saved analytics for custom event.")
    case .failure(let error):
        print(error)
    }
}

//: You can also add dimensions to your analytics.
friendEvent.track(dimensions: ["more": "info"]) { result in
    switch result {
    case .success:
        print("Saved analytics for custom event with dimensions.")
    case .failure(let error):
        print(error)
    }
}