@analytics/hubspot
Advanced tools
Comparing version 0.1.2 to 0.2.0
@@ -6,2 +6,13 @@ # Change Log | ||
# 0.2.0 (2019-10-14) | ||
### Features | ||
* **hubspot:** add HubSpot plugin ([799c7f7](https://github.com/DavidWells/analytics/commit/799c7f7)) | ||
## [0.1.2](https://github.com/DavidWells/analytics/compare/analytics-plugin-hubspot@0.1.1...analytics-plugin-hubspot@0.1.2) (2019-10-04) | ||
@@ -8,0 +19,0 @@ |
@@ -57,3 +57,3 @@ var analyticsHubspot = (function () { | ||
*/ | ||
function hubSpotPlugin() { | ||
function hubSpotPlugin$1() { | ||
var pluginConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -94,3 +94,13 @@ // Because hubspot automatically fired a page view onLoad. We need to ignore the first .page() call | ||
}, | ||
// https://developers.hubspot.com/docs/methods/tracking_code_api/identify_visitor | ||
/** | ||
* Identify a visitor in hubspot | ||
* @link https://developers.hubspot.com/docs/methods/tracking_code_api/identify_visitor | ||
* @example | ||
* | ||
* analytics.identify({ | ||
* name: 'bob', | ||
* email: 'bob@bob.com' // email is required | ||
* }) | ||
*/ | ||
identify: function identify(_ref2) { | ||
@@ -145,3 +155,3 @@ var payload = _ref2.payload, | ||
}; | ||
} // Todo expose as option if needed | ||
} | ||
@@ -204,3 +214,3 @@ function defaultFormatter(key, value) { | ||
var index = hubSpotPlugin; | ||
var index = hubSpotPlugin$1; | ||
@@ -207,0 +217,0 @@ return index; |
@@ -56,3 +56,3 @@ 'use strict'; | ||
*/ | ||
function hubSpotPlugin() { | ||
function hubSpotPlugin$1() { | ||
var pluginConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -93,3 +93,13 @@ // Because hubspot automatically fired a page view onLoad. We need to ignore the first .page() call | ||
}, | ||
// https://developers.hubspot.com/docs/methods/tracking_code_api/identify_visitor | ||
/** | ||
* Identify a visitor in hubspot | ||
* @link https://developers.hubspot.com/docs/methods/tracking_code_api/identify_visitor | ||
* @example | ||
* | ||
* analytics.identify({ | ||
* name: 'bob', | ||
* email: 'bob@bob.com' // email is required | ||
* }) | ||
*/ | ||
identify: function identify(_ref2) { | ||
@@ -144,3 +154,3 @@ var payload = _ref2.payload, | ||
}; | ||
} // Todo expose as option if needed | ||
} | ||
@@ -203,4 +213,4 @@ function defaultFormatter(key, value) { | ||
var index = hubSpotPlugin; | ||
var index = hubSpotPlugin$1; | ||
module.exports = index; |
@@ -54,3 +54,3 @@ function _slicedToArray(arr, i) { | ||
*/ | ||
function hubSpotPlugin() { | ||
function hubSpotPlugin$1() { | ||
var pluginConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -91,3 +91,13 @@ // Because hubspot automatically fired a page view onLoad. We need to ignore the first .page() call | ||
}, | ||
// https://developers.hubspot.com/docs/methods/tracking_code_api/identify_visitor | ||
/** | ||
* Identify a visitor in hubspot | ||
* @link https://developers.hubspot.com/docs/methods/tracking_code_api/identify_visitor | ||
* @example | ||
* | ||
* analytics.identify({ | ||
* name: 'bob', | ||
* email: 'bob@bob.com' // email is required | ||
* }) | ||
*/ | ||
identify: function identify(_ref2) { | ||
@@ -142,3 +152,3 @@ var payload = _ref2.payload, | ||
}; | ||
} // Todo expose as option if needed | ||
} | ||
@@ -201,4 +211,4 @@ function defaultFormatter(key, value) { | ||
var index = hubSpotPlugin; | ||
var index = hubSpotPlugin$1; | ||
export default index; |
@@ -46,3 +46,3 @@ 'use strict'; | ||
function hubspotPlugin() { | ||
function hubSpotPlugin() { | ||
var userConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -90,4 +90,4 @@ // Allow for userland overides of base methods | ||
var index = hubspotPlugin; | ||
var index = hubSpotPlugin; | ||
module.exports = index; |
@@ -44,3 +44,3 @@ function _defineProperty(obj, key, value) { | ||
function hubspotPlugin() { | ||
function hubSpotPlugin() { | ||
var userConfig = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
@@ -88,4 +88,4 @@ // Allow for userland overides of base methods | ||
var index = hubspotPlugin; | ||
var index = hubSpotPlugin; | ||
export default index; |
{ | ||
"name": "@analytics/hubspot", | ||
"version": "0.1.2", | ||
"version": "0.2.0", | ||
"description": "HubSpot plugin for 'analytics' module", | ||
"projectMeta": { | ||
"provider": { | ||
"name": "HubSpot", | ||
"url": "https://hubspot.com/" | ||
}, | ||
"platforms": { | ||
"browser": "./src/browser.js" | ||
} | ||
}, | ||
"keywords": [ | ||
@@ -44,3 +53,4 @@ "analytics", | ||
"@babel/preset-env": "^7.3.1" | ||
} | ||
}, | ||
"gitHead": "159c0f42b5af886af963a0a65e1f5c3c33f023f2" | ||
} |
215
README.md
@@ -0,1 +1,5 @@ | ||
<!-- | ||
title: HubSpot | ||
description: Using the HubSpot analytics plugin | ||
--> | ||
# HubSpot plugin for `analytics` | ||
@@ -5,13 +9,23 @@ | ||
This analytics plugin will load HubSpot's client side tracking script into your application and send custom events, page views, and identify visitors inside HubSpot. | ||
[View the docs](https://getanalytics.io/plugins/hubspot/) | ||
<!-- ANALYTICS_DOCS:START (TOC) --> | ||
- [Usage](#usage) | ||
<!-- AUTO-GENERATED-CONTENT:START (TOC:collapse=true&collapseText=Click to expand) --> | ||
<details> | ||
<summary>Click to expand</summary> | ||
- [Installation](#installation) | ||
- [How to use](#how-to-use) | ||
- [Browser usage](#browser-usage) | ||
* [Browser API](#browser-api) | ||
- [Platforms Supported](#platforms-supported) | ||
- [Additional examples](#additional-examples) | ||
- [Using identify](#using-identify) | ||
- [Configuration](#configuration) | ||
- [Plugin Options](#plugin-options) | ||
<!-- ANALYTICS_DOCS:END (TOC) --> | ||
## Usage | ||
</details> | ||
<!-- AUTO-GENERATED-CONTENT:END (TOC) --> | ||
## Installation | ||
Install `analytics` and `@analytics/hubspot` packages | ||
@@ -24,4 +38,10 @@ | ||
Import and initialize in project | ||
<!-- AUTO-GENERATED-CONTENT:START (PLUGIN_DOCS) --> | ||
## How to use | ||
The `@analytics/hubspot` package works in [the browser](#browser-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 | ||
@@ -40,49 +60,180 @@ import Analytics from 'analytics' | ||
/* Track page views */ | ||
/* Track a page view */ | ||
analytics.page() | ||
/* Track custom events */ | ||
analytics.track('buttonClicked') | ||
/* Track a custom event */ | ||
analytics.track('cartCheckout', { | ||
item: 'pink socks', | ||
price: 20 | ||
}) | ||
/* Identify visitors */ | ||
analytics.identify('user-xzy-123', { | ||
email: 'bill@murray.com', | ||
accountLevel: 'pro' | ||
/* Identify a visitor */ | ||
analytics.identify({ | ||
name: 'bob', | ||
email: 'bob@bob.com' // email is required | ||
}) | ||
``` | ||
## Using identify | ||
After initializing `analytics` with the `hubSpotPlugin` plugin, data will be sent into HubSpot whenever [analytics.identify](https://getanalytics.io/api/#analyticsidentify), [analytics.page](https://getanalytics.io/api/#analyticspage), or [analytics.track](https://getanalytics.io/api/#analyticstrack) are called. | ||
**Important:** HubSpot requires an `email` field for making identify calls. | ||
See [additional implementation examples](#additional-examples) for more details on using in your project. | ||
If your identify call does not contain `email` HubSpot will not be notified of the new user. | ||
## Browser usage | ||
When sending properties with `identify` calls, all `camelCase` traits are automatically converted to `snake_case`. There is one exception to this for `firstName` & `lastName` which are sent as `firstname` & `lastname`. | ||
The HubSpot client side browser plugin works with these analytic api methods: | ||
**Example:** | ||
- **[analytics.identify](https://getanalytics.io/api/#analyticsidentify)** - Identify visitors and send details to HubSpot | ||
- **[analytics.page](https://getanalytics.io/api/#analyticspage)** - Sends page views into HubSpot | ||
- **[analytics.track](https://getanalytics.io/api/#analyticstrack)** - Track custom events and send to HubSpot | ||
### Browser API | ||
```js | ||
analytics.identify('user-xzy-123', { | ||
email: 'bill@murray.com', | ||
accountLevel: 'pro' // trait will be `account_level` | ||
const analytics = Analytics({ | ||
app: 'awesome-app', | ||
plugins: [ | ||
hubSpotPlugin({ | ||
portalId: '234576' | ||
}) | ||
] | ||
}) | ||
``` | ||
## Configuration | ||
**Initialization arguments** | ||
<!-- ANALYTICS_DOCS:START (API) --> | ||
## Plugin Options | ||
- **pluginConfig** `object` Plugin settings | ||
- **pluginConfig.portalId** `string` The HubSpot Portal (or Hub) Id of your HubSpot account | ||
**Arguments** | ||
- **pluginConfig** <code>object</code> - Plugin settings | ||
- **pluginConfig.portalId** <code>string</code> - The HubSpot Portal (or Hub) Id of your HubSpot account | ||
## Platforms Supported | ||
**Example** | ||
The `@analytics/hubspot` package works in [the browser](#browser-usage) | ||
## Additional examples | ||
Below are additional implementation examples. | ||
<details> | ||
<summary>Using in HTML</summary> | ||
Below is an example of importing via the unpkg CDN. Please note this will pull in the latest version of the package. | ||
```html | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Using @analytics/hubspot in HTML</title> | ||
<script src="https://unpkg.com/analytics/dist/analytics.min.js"></script> | ||
<script src="https://unpkg.com/@analytics/hubspot/dist/@analytics/hubspot.min.js"></script> | ||
<script type="text/javascript"> | ||
/* Initialize analytics */ | ||
var Analytics = _analytics.init({ | ||
app: 'my-app-name', | ||
plugins: [ | ||
analyticsHubspot({ | ||
portalId: '234576' | ||
}) | ||
] | ||
}) | ||
/* Track a page view */ | ||
analytics.page() | ||
/* Track a custom event */ | ||
analytics.track('cartCheckout', { | ||
item: 'pink socks', | ||
price: 20 | ||
}) | ||
/* Identify a visitor */ | ||
analytics.identify({ | ||
name: 'bob', | ||
email: 'bob@bob.com' // email is required | ||
}) | ||
</script> | ||
</head> | ||
<body> | ||
.... | ||
</body> | ||
</html> | ||
``` | ||
</details> | ||
<details> | ||
<summary>Using in HTML via ES Modules</summary> | ||
Using `@analytics/hubspot` in ESM modules. | ||
```html | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Using @analytics/hubspot 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 analyticsHubspot from 'https://unpkg.com/@analytics/hubspot/lib/analytics-plugin-hubspot.browser.es.js?module' | ||
/* Initialize analytics */ | ||
const Analytics = analytics({ | ||
app: 'analytics-html-demo', | ||
debug: true, | ||
plugins: [ | ||
analyticsHubspot({ | ||
portalId: '234576' | ||
}) | ||
// ... add any other third party analytics plugins | ||
] | ||
}) | ||
/* Track a page view */ | ||
analytics.page() | ||
/* Track a custom event */ | ||
analytics.track('cartCheckout', { | ||
item: 'pink socks', | ||
price: 20 | ||
}) | ||
/* Identify a visitor */ | ||
analytics.identify({ | ||
name: 'bob', | ||
email: 'bob@bob.com' // email is required | ||
}) | ||
</script> | ||
</head> | ||
<body> | ||
.... | ||
</body> | ||
</html> | ||
``` | ||
</details> | ||
<!-- AUTO-GENERATED-CONTENT:END (PLUGIN_DOCS) --> | ||
## Using identify | ||
**Important:** HubSpot requires an `email` field for making identify calls. | ||
If your identify call does not contain `email` HubSpot will not be notified of the new user. | ||
When sending properties with `identify` calls, all `camelCase` traits are automatically converted to `snake_case`. There is one exception to this for `firstName` & `lastName` which are sent as `firstname` & `lastname`. | ||
**Example:** | ||
```js | ||
hubSpotPlugin({ | ||
portalId: '234576' | ||
analytics.identify('user-xzy-123', { | ||
email: 'bill@murray.com', | ||
accountLevel: 'pro' // trait will be `account_level` | ||
}) | ||
``` | ||
<!-- ANALYTICS_DOCS:END --> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34862
670
237