Skip to content

Commit e614e3e

Browse files
Add integration chartbeat This commit copies the content of the integration repo into the "integrations" folder. Original repo: https://github.com/segment-integrations/analytics.js-integration-chartbeat Readme: https://github.com/segment-integrations/analytics.js-integration-chartbeat/blob/master/README.md
1 parent b879f94 commit e614e3e

File tree

6 files changed

+455
-0
lines changed

6 files changed

+455
-0
lines changed

integrations/chartbeat/HISTORY.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
2.2.2 / 2018-03-26
2+
==================
3+
4+
* [Fix](https://github.com/segment-integrations/analytics.js-integration-chartbeat/pull/8): Send `document.title` as *title* to Chartbeat.
5+
6+
2.2.1 / 2017-12-19
7+
==================
8+
9+
* Smarter assumesPageView + feature addition: subscriber engagement
10+
* no yarn.lock
11+
12+
2.2.0 / 2017-12-19
13+
==================
14+
15+
* better tests
16+
* removed exclusive test
17+
* changed subscriber engagement setting from obj to array
18+
* added comments
19+
* initial commit
20+
2.1.0 / 2017-08-29
21+
==================
22+
23+
* Bump analytics.js-integration to ^3.2.0
24+
25+
2.0.0 / 2016-06-21
26+
==================
27+
28+
* Remove Duo compatibility
29+
* Add CI setup (coverage, linting, cross-browser compatibility, etc.)
30+
* Update eslint configuration
31+
32+
1.0.6 / 2016-05-07
33+
==================
34+
35+
* Bump Analytics.js core, tester, integration to use Facade 2.x
36+
37+
1.0.5 / 2015-07-07
38+
==================
39+
40+
* Allow loading of video tag instead of normal Chartbeat tag
41+
42+
1.0.4 / 2015-06-30
43+
==================
44+
45+
* Replace analytics.js dependency with analytics.js-core
46+
47+
1.0.3 / 2015-06-30
48+
==================
49+
50+
* Replace analytics.js dependency with analytics.js-core
51+
52+
1.0.2 / 2015-06-24
53+
==================
54+
55+
* Bump analytics.js-integration version
56+
57+
1.0.1 / 2015-06-24
58+
==================
59+
60+
* Bump analytics.js-integration version
61+
62+
1.0.0 / 2015-06-09
63+
==================
64+
65+
* Initial commit :sparkles:

integrations/chartbeat/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# analytics.js-integration-chartbeat [![Build Status][ci-badge]][ci-link]
2+
3+
Chartbeat integration for [Analytics.js][].
4+
5+
## License
6+
7+
Released under the [MIT license](LICENSE).
8+
9+
10+
[Analytics.js]: https://segment.com/docs/libraries/analytics.js/
11+
[ci-link]: https://circleci.com/gh/segment-integrations/analytics.js-integration-chartbeat
12+
[ci-badge]: https://circleci.com/gh/segment-integrations/analytics.js-integration-chartbeat.svg?style=svg
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var defaults = require('@ndhoule/defaults');
8+
var integration = require('@segment/analytics.js-integration');
9+
var onBody = require('on-body');
10+
11+
/**
12+
* Expose `Chartbeat` integration.
13+
*/
14+
15+
var Chartbeat = module.exports = integration('Chartbeat')
16+
.global('_sf_async_config')
17+
.global('_sf_endpt')
18+
.global('pSUPERFLY')
19+
.option('domain', '')
20+
.option('uid', null)
21+
.option('video', false)
22+
.option('sendNameAndCategoryAsTitle', false)
23+
.option('subscriberEngagementKeys', [])
24+
25+
.tag('<script src="//static.chartbeat.com/js/{{ script }}">');
26+
27+
/**
28+
* Loaded?
29+
*
30+
* @api private
31+
* @return {boolean}
32+
*/
33+
34+
Chartbeat.prototype.loaded = function() {
35+
return !!window.pSUPERFLY;
36+
};
37+
38+
Chartbeat.prototype.initialize = function() {
39+
this.pageCalledYet = false;
40+
this._ready = true; // temporarily switch ready to true so that a single page call can fire
41+
};
42+
43+
/**
44+
* Page.
45+
*
46+
* http://chartbeat.com/docs/handling_virtual_page_changes/
47+
*
48+
* @api public
49+
* @param {Page} page
50+
*/
51+
52+
Chartbeat.prototype.page = function(page) {
53+
this.updateConfig(page);
54+
55+
// since chartbeat automatically calls a page when it loads, don't load chartbeat script until
56+
// first Segment page call comes in and configures global config vars using its props
57+
if (!this.pageCalledYet) {
58+
this._ready = false; // switch ready to false so that no pages after the first one can fire until _initialize has loaded chartbeat script
59+
this.pageCalledYet = true;
60+
this._initialize();
61+
} else {
62+
var props = page.properties();
63+
window.pSUPERFLY.virtualPage(props.path);
64+
}
65+
};
66+
67+
// update chartbeat global config vars
68+
Chartbeat.prototype.updateConfig = function(page) {
69+
var category = page.category();
70+
var author = page.proxy('properties.author');
71+
var props = page.properties();
72+
73+
// Chartbeat expects the document.title (props.title) to populate as title
74+
// This maintains legacy behavior for existing users,
75+
// defaults new users to the correct behavior,
76+
// and allows current users to opt-in to the correct behavior.
77+
// http://support.chartbeat.com/docs/#titles
78+
var title;
79+
if (this.options.sendNameAndCategoryAsTitle) {
80+
title = page.fullName() || props.title;
81+
} else {
82+
title = props.title;
83+
}
84+
85+
// update general config
86+
window._sf_async_config = window._sf_async_config || {};
87+
88+
if (category) window._sf_async_config.sections = category;
89+
if (author) window._sf_async_config.authors = author;
90+
if (title) window._sf_async_config.title = title;
91+
92+
// update subscriber engagement
93+
var _cbq = window._cbq = window._cbq || [];
94+
95+
for (var key in props) {
96+
if (!props.hasOwnProperty(key)) continue;
97+
if (this.options.subscriberEngagementKeys.indexOf(key) > -1) {
98+
_cbq.push([key, props[key]]);
99+
}
100+
}
101+
};
102+
103+
// sets global vars and loads Chartbeat script
104+
Chartbeat.prototype._initialize = function() {
105+
var self = this;
106+
var script = this.options.video ? 'chartbeat_video.js' : 'chartbeat.js';
107+
108+
window._sf_async_config.useCanonical = true;
109+
defaults(window._sf_async_config, {
110+
domain: this.options.domain,
111+
uid: this.options.uid
112+
});
113+
114+
onBody(function() {
115+
window._sf_endpt = new Date().getTime();
116+
// Note: Chartbeat depends on document.body existing so the script does
117+
// not load until that is confirmed. Otherwise it may trigger errors.
118+
self.load({ script: script }, self.ready); // switch ready to true for real once the script has loaded
119+
});
120+
};
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"name": "@segment/analytics.js-integration-chartbeat",
3+
"description": "The Chartbeat analytics.js integration.",
4+
"version": "2.2.2",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"chartbeat"
10+
],
11+
"main": "lib/index.js",
12+
"scripts": {
13+
"test": "make test"
14+
},
15+
"author": "Segment \u003c[email protected]\u003e",
16+
"license": "SEE LICENSE IN LICENSE",
17+
"homepage": "https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/chartbeat#readme",
18+
"bugs": {
19+
"url": "https://github.com/segmentio/analytics.js-integrations/issues"
20+
},
21+
"repository": {
22+
"type": "git",
23+
"url": "git+https://github.com/segmentio/analytics.js-integrations.git"
24+
},
25+
"dependencies": {
26+
"@ndhoule/defaults": "^2.0.1",
27+
"@segment/analytics.js-integration": "^3.2.0",
28+
"on-body": "0.0.1"
29+
},
30+
"devDependencies": {
31+
"@ndhoule/extend": "^2.0.0",
32+
"@segment/analytics.js-core": "^3.0.0",
33+
"@segment/analytics.js-integration-tester": "^3.1.0",
34+
"@segment/clear-env": "^2.0.0",
35+
"@segment/eslint-config": "^3.1.1",
36+
"browserify": "^13.0.0",
37+
"browserify-istanbul": "^2.0.0",
38+
"eslint": "^2.9.0",
39+
"eslint-plugin-mocha": "^2.2.0",
40+
"eslint-plugin-require-path-exists": "^1.1.5",
41+
"istanbul": "^0.4.3",
42+
"karma": "1.3.0",
43+
"karma-browserify": "^5.0.4",
44+
"karma-chrome-launcher": "^1.0.1",
45+
"karma-coverage": "^1.0.0",
46+
"karma-junit-reporter": "^1.0.0",
47+
"karma-mocha": "1.0.1",
48+
"karma-phantomjs-launcher": "^1.0.0",
49+
"karma-sauce-launcher": "^1.0.0",
50+
"karma-spec-reporter": "0.0.26",
51+
"mocha": "^2.2.5",
52+
"npm-check": "^5.2.1",
53+
"phantomjs-prebuilt": "^2.1.7",
54+
"watchify": "^3.7.0"
55+
}
56+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@segment/eslint-config/mocha"
3+
}

0 commit comments

Comments
 (0)