# Custify plugin for `analytics` Integration with Custify for [analytics](https://www.npmjs.com/package/analytics) This analytics plugin will load Custify's client side tracking script into your application and send custom events, page views, and identify visitors inside Custify. [View the docs](https://getanalytics.io/plugins/custify/)
Click to expand - [Custify plugin for `analytics`](#custify-plugin-for-analytics) - [Installation](#installation) - [How to use](#how-to-use) - [Platforms Supported](#platforms-supported) - [Browser usage](#browser-usage) - [Browser API](#browser-api) - [Configuration options for browser](#configuration-options-for-browser) - [Server-side usage](#server-side-usage) - [Server-side API](#server-side-api) - [Configuration options for server-side](#configuration-options-for-server-side) - [Additional examples](#additional-examples)
## Installation Install `analytics` and `@analytics/custify` packages ```bash npm install analytics npm install @analytics/custify ``` ## How to use The `@analytics/custify` package works in [the browser](#browser-usage) and [server-side in Node.js](#server-side-usage). To use, install the package, include in your project and initialize the plugin with [analytics](https://www.npmjs.com/package/analytics). Below is an example of how to use the browser plugin. ```js import Analytics from 'analytics' import custifyPlugin from '@analytics/custify' const analytics = Analytics({ app: 'awesome-app', plugins: [ // This will load crazy egg on to the page custifyPlugin({ accountId: '1234578' }) ] }) /* Track a page view */ analytics.page() /* Track a custom event */ analytics.track('cartCheckout', { item: 'pink socks', price: 20 }) /* Identify a visitor */ analytics.identify('user-id-xyz', { firstName: 'bill', lastName: 'murray' }) ``` After initializing `analytics` with the `custifyPlugin` plugin, data will be sent into Custify whenever [analytics.page](https://getanalytics.io/api/#analyticspage), [analytics.track](https://getanalytics.io/api/#analyticstrack), or [analytics.identify](https://getanalytics.io/api/#analyticsidentify) are called. See [additional implementation examples](#additional-examples) for more details on using in your project. ## Platforms Supported The `@analytics/custify` package works in [the browser](#browser-usage) and [server-side in Node.js](#server-side-usage) ## Browser usage The Custify client side browser plugin works with these analytic api methods: - **[analytics.identify](https://getanalytics.io/api/#analyticsidentify)** - Identify visitors and send details to Custify - **[analytics.page](https://getanalytics.io/api/#analyticspage)** - Sends page views into Custify - **[analytics.track](https://getanalytics.io/api/#analyticstrack)** - Track custom events and send to Custify ### Browser API ```js import Analytics from 'analytics' import custifyPlugin from '@analytics/custify' const analytics = Analytics({ app: 'awesome-app', plugins: [ // This will load crazy egg on to the page custifyPlugin({ accountId: '1234578' }) ] }) ``` ### Configuration options for browser | Option | description | |:---------------------------|:-----------| | `accountId`
**required** - string| custify account ID | | `scriptInclude`
_optional_ - boolean| Load custify script into page | | `options`
_optional_ - object| Custify script options | ## Server-side usage The Custify server-side node.js plugin works with these analytic api methods: - **[analytics.page](https://getanalytics.io/api/#analyticspage)** - Sends page views into Custify - **[analytics.track](https://getanalytics.io/api/#analyticstrack)** - Track custom events and send to Custify - **[analytics.identify](https://getanalytics.io/api/#analyticsidentify)** - Identify visitors and send details to Custify ### Server-side API ```js import Analytics from 'analytics' import custifyPlugin from '@analytics/custify' const analytics = Analytics({ app: 'awesome-app', plugins: [ custifyPlugin({ apiKey: 'abc123' }) ] }) ``` ### Configuration options for server-side | Option | description | |:---------------------------|:-----------| | `apiKey`
**required** - string| custify API key | ## Additional examples Below are additional implementation examples.
Server-side ES6 ```js import Analytics from 'analytics' import custifyPlugin from '@analytics/custify' const analytics = Analytics({ app: 'awesome-app', plugins: [ custifyPlugin({ apiKey: 'abc123' }) // ...other plugins ] }) /* Track a page view */ analytics.page() /* Track a custom event */ analytics.track('cartCheckout', { item: 'pink socks', price: 20 }) /* Identify a visitor */ analytics.identify('user-id-xyz', { firstName: 'bill', lastName: 'murray' }) ```
Server-side Node.js with common JS If using node, you will want to import the `.default` ```js const analyticsLib = require('analytics').default const custifyPlugin = require('@analytics/custify').default const analytics = analyticsLib({ app: 'my-app-name', plugins: [ custifyPlugin({ apiKey: 'abc123' }) ] }) /* Track a page view */ analytics.page() /* Track a custom event */ analytics.track('cartCheckout', { item: 'pink socks', price: 20 }) /* Identify a visitor */ analytics.identify('user-id-xyz', { firstName: 'bill', lastName: 'murray' }) ```
Using in HTML Below is an example of importing via the unpkg CDN. Please note this will pull in the latest version of the package. ```html Using @analytics/custify in HTML .... ```
Using in HTML via ES Modules Using `@analytics/custify` in ESM modules. ```html Using @analytics/custify in HTML via ESModules .... ```