Skip to content

Commit 2dd46f7

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

File tree

6 files changed

+629
-0
lines changed

6 files changed

+629
-0
lines changed

integrations/foxmetrics/HISTORY.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
2.2.0 / 2016-09-07
3+
==================
4+
5+
* support ecom specv2
6+
7+
2.1.1 / 2016-08-16
8+
==================
9+
10+
* Fix for release
11+
12+
2.1.0 / 2016-08-16
13+
==================
14+
15+
* Merge pull request #2 from segment-integrations/update/ecommerce-spec-v2
16+
* update ecommerce spec syntax to v2
17+
18+
2.0.0 / 2016-06-21
19+
==================
20+
21+
* Remove Duo compatibility
22+
* Add CI setup (coverage, linting, cross-browser compatibility, etc.)
23+
* Update eslint configuration
24+
25+
1.0.5 / 2016-05-07
26+
==================
27+
28+
* Bump Analytics.js core, tester, integration to use Facade 2.x
29+
30+
1.0.4 / 2015-06-30
31+
==================
32+
33+
* Replace analytics.js dependency with analytics.js-core
34+
35+
1.0.3 / 2015-06-30
36+
==================
37+
38+
* Replace analytics.js dependency with analytics.js-core
39+
40+
1.0.2 / 2015-06-24
41+
==================
42+
43+
* Bump analytics.js-integration version
44+
45+
1.0.1 / 2015-06-24
46+
==================
47+
48+
* Bump analytics.js-integration version
49+
50+
1.0.0 / 2015-06-09
51+
==================
52+
53+
* Initial commit :sparkles:

integrations/foxmetrics/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# analytics.js-integration-foxmetrics [![Build Status][ci-badge]][ci-link]
2+
3+
Foxmetrics 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-foxmetrics
12+
[ci-badge]: https://circleci.com/gh/segment-integrations/analytics.js-integration-foxmetrics.svg?style=svg
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var Track = require('segmentio-facade').Track;
8+
var each = require('component-each');
9+
var integration = require('@segment/analytics.js-integration');
10+
var push = require('global-queue')('_fxm');
11+
12+
/**
13+
* Expose `FoxMetrics` integration.
14+
*/
15+
16+
var FoxMetrics = module.exports = integration('FoxMetrics')
17+
.assumesPageview()
18+
.global('_fxm')
19+
.option('appId', '')
20+
.tag('<script src="//d35tca7vmefkrc.cloudfront.net/scripts/{{ appId }}.js">');
21+
22+
/**
23+
* Initialize.
24+
*
25+
* http://foxmetrics.com/documentation/apijavascript
26+
*
27+
* @api public
28+
*/
29+
30+
FoxMetrics.prototype.initialize = function() {
31+
window._fxm = window._fxm || [];
32+
this.load(this.ready);
33+
};
34+
35+
/**
36+
* Loaded?
37+
*
38+
* @return {Boolean}
39+
*/
40+
41+
FoxMetrics.prototype.loaded = function() {
42+
return !!(window._fxm && window._fxm.appId);
43+
};
44+
45+
/**
46+
* Page.
47+
*
48+
* @api public
49+
* @param {Page} page
50+
*/
51+
52+
FoxMetrics.prototype.page = function(page) {
53+
var properties = page.properties();
54+
var category = page.category();
55+
var name = page.name();
56+
// store for later
57+
// TODO: Why? Document me
58+
this._category = category;
59+
60+
push(
61+
'_fxm.pages.view',
62+
properties.title,
63+
name,
64+
category,
65+
properties.url,
66+
properties.referrer
67+
);
68+
};
69+
70+
/**
71+
* Identify.
72+
*
73+
* @api public
74+
* @param {Identify} identify
75+
*/
76+
77+
FoxMetrics.prototype.identify = function(identify) {
78+
var id = identify.userId();
79+
80+
if (!id) return;
81+
82+
push(
83+
'_fxm.visitor.profile',
84+
id,
85+
identify.firstName(),
86+
identify.lastName(),
87+
identify.email(),
88+
identify.address(),
89+
// social
90+
// TODO: Why is this `undefined`? Document
91+
undefined,
92+
// partners
93+
// TODO: Why is this `undefined`? Document
94+
undefined,
95+
identify.traits()
96+
);
97+
};
98+
99+
/**
100+
* Track.
101+
*
102+
* @api public
103+
* @param {Track} track
104+
*/
105+
106+
FoxMetrics.prototype.track = function(track) {
107+
var props = track.properties();
108+
var category = this._category || props.category;
109+
push(track.event(), category, props);
110+
};
111+
112+
/**
113+
* Product viewed.
114+
*
115+
* @api private
116+
* @param {Track} track
117+
*/
118+
119+
FoxMetrics.prototype.productViewed = function(track) {
120+
ecommerce('productview', track);
121+
};
122+
123+
/**
124+
* Product Removed.
125+
*
126+
* @api private
127+
* @param {Track} track
128+
*/
129+
130+
FoxMetrics.prototype.productRemoved = function(track) {
131+
ecommerce('removecartitem', track);
132+
};
133+
134+
/**
135+
* Product Added.
136+
*
137+
* @api private
138+
* @param {Track} track
139+
*/
140+
141+
FoxMetrics.prototype.productAdded = function(track) {
142+
ecommerce('cartitem', track);
143+
};
144+
145+
/**
146+
* Order Completed.
147+
*
148+
* @api private
149+
* @param {Track} track
150+
*/
151+
152+
FoxMetrics.prototype.orderCompleted = function(track) {
153+
var orderId = track.orderId();
154+
155+
// transaction
156+
push(
157+
'_fxm.ecommerce.order',
158+
orderId,
159+
track.subtotal(),
160+
track.shipping(),
161+
track.tax(),
162+
track.city(),
163+
track.state(),
164+
track.zip(),
165+
track.quantity()
166+
);
167+
168+
// items
169+
each(track.products(), function(product) {
170+
var track = new Track({ properties: product });
171+
ecommerce('purchaseitem', track, [
172+
track.quantity(),
173+
track.price(),
174+
orderId
175+
]);
176+
});
177+
};
178+
179+
/**
180+
* Track ecommerce `event` with `track`
181+
* with optional `arr` to append.
182+
*
183+
* @api private
184+
* @param {string} event
185+
* @param {Track} track
186+
* @param {Array} arr
187+
*/
188+
189+
function ecommerce(event, track, arr) {
190+
push.apply(null, [
191+
'_fxm.ecommerce.' + event,
192+
track.productId() || track.id() || track.sku(),
193+
track.name(),
194+
track.category()
195+
].concat(arr || []));
196+
}
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-foxmetrics",
3+
"description": "The Foxmetrics analytics.js integration.",
4+
"version": "2.2.0",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"foxmetrics"
10+
],
11+
"main": "lib/index.js",
12+
"scripts": {
13+
"test": "make test"
14+
},
15+
"author": "Segment \u003cfriends@segment.com\u003e",
16+
"license": "SEE LICENSE IN LICENSE",
17+
"homepage": "https://github.com/segmentio/analytics.js-integrations/blob/master/integrations/foxmetrics#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+
"@segment/analytics.js-integration": "^3.1.0",
27+
"component-each": "^0.2.6",
28+
"global-queue": "^1.0.1",
29+
"segmentio-facade": "^3.0.3"
30+
},
31+
"devDependencies": {
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)