0.1.2 • Published 1 year ago

@analytics/ownstats v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Ownstats plugin for analytics

Integration with Ownstats for analytics

For more information see the docs.

Installation

npm install analytics
npm install @analytics/ownstats

How to use

The @analytics/ownstats package works in the browser and server-side in Node.js. To use, install the package, include in your project and initialize the plugin with analytics.

Below is an example of how to use the browser plugin.

import Analytics from 'analytics'
import ownstatsPlugin from '@analytics/ownstats'

const analytics = Analytics({
  app: 'awesome-app',
  plugins: [
    ownstatsPlugin({
      endpoint: 'my.ownstats.cloud',
      useAutomation: true,
      debug: true
    })
  ]
})

/* Track a page view */
analytics.page()

After initializing analytics with the ownstatsPlugin plugin, data will be sent into Ownstats whenever or analytics.page are called.

See additional implementation examples for more details on using in your project.

Platforms Supported

The @analytics/ownstats package works in the browser and server-side in Node.js

Browser usage

The Ownstats client side browser plugin works with these analytic api methods:

Browser API

import Analytics from 'analytics'
import ownstatsPlugin from '@analytics/ownstats'

const analytics = Analytics({
  app: 'awesome-app',
  plugins: [
    ownstatsPlugin({
      endpoint: 'my.ownstats.cloud',
      useAutomation: true,
      debug: true
    })
  ]
})

Configuration options for browser

Optiondescription
endpoint required - stringYour Ownstats endpoint
useAutomation required - booleanAutomatically trigger pageviews upon route changes for single page applications
debug required - boolenaDebug mode (necessary for localhost testing)

Server-side usage

The Ownstats server-side node.js plugin works with these analytic api methods:

Server-side API

import Analytics from 'analytics'
import ownstatsPlugin from '@analytics/ownstats'

const analytics = Analytics({
  app: 'awesome-app',
  plugins: [
    ownstatsPlugin({
      endpoint: 'my.ownstats.cloud'
    })
  ]
})

Configuration options for server-side

Optiondescription
endpoint required - stringYour Ownstats endpoint

Additional examples

Below are additional implementation examples.

import Analytics from 'analytics'
import ownstatsPlugin from '@analytics/ownstats'

const analytics = Analytics({
  app: 'awesome-app',
  plugins: [
    ownstatsPlugin({
      endpoint: 'my.ownstats.cloud'
    })
    // ...other plugins
  ]
})

/* Track a page view */
analytics.page()

If using node, you will want to import the .default

const analyticsLib = require('analytics').default
const ownstatsPlugin = require('@analytics/ownstats').default

const analytics = analyticsLib({
  app: 'my-app-name',
  plugins: [
    ownstatsPlugin({
      endpoint: 'my.ownstats.cloud'
    })
  ]
})

/* Track a page view */
analytics.page()

Below is an example of importing via the unpkg CDN. Please note this will pull in the latest version of the package.

<!DOCTYPE html>
<html>
  <head>
    <title>Using @analytics/ownstats in HTML</title>
    <script src="https://unpkg.com/analytics/dist/analytics.min.js"></script>
    <script src="https://unpkg.com/@analytics/ownstats/dist/@analytics/ownstats.min.js"></script>
    <script type="text/javascript">
      /* Initialize analytics */
      var Analytics = _analytics.init({
        app: 'my-app-name',
        plugins: [
          analyticsOwnstats({
            endpoint: 'my.ownstats.cloud',
            useAutomation: true,
            debug: true
          })
        ]
      })

      /* Track a page view */
      analytics.page()
    </script>
  </head>
  <body>
    ....
  </body>
</html>

Using @analytics/ownstats in ESM modules.

<!DOCTYPE html>
<html>
  <head>
    <title>Using @analytics/ownstats in HTML via ESModules</title>
    <script>
      // Polyfill process.
      // **Note**: Because `import`s are hoisted, we need a separate, prior <script> block.
      window.process = window.process || { env: { NODE_ENV: 'production' } }
    </script>
    <script type="module">
      import analytics from 'https://unpkg.com/analytics/lib/analytics.browser.es.js?module'
      import analyticsOwnstats from 'https://unpkg.com/@analytics/ownstats/lib/analytics-plugin-ownstats.browser.es.js?module'
      /* Initialize analytics */
      const Analytics = analytics({
        app: 'analytics-html-demo',
        debug: true,
        plugins: [
          analyticsOwnstats({
            endpoint: 'my.ownstats.cloud',
            useAutomation: true,
            debug: true
          })
          // ... add any other third party analytics plugins
        ]
      })

      /* Track a page view */
      analytics.page()
    </script>
  </head>
  <body>
    ....
  </body>
</html>

See the full list of analytics provider plugins in the main repo.

0.1.2

1 year ago

0.1.1

2 years ago

0.1.0

2 years ago