Skip to content

Commit b784208

Browse files
author
Nathan Houle
committed
Remove Duo support, add Browserify support, modernize test harness (#49)
1 parent 0666cb2 commit b784208

24 files changed

+703
-6343
lines changed

.eslintrc

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
11
{
2-
"extends": "segment/browser",
3-
4-
"rules": {
5-
"global-strict": 0,
6-
"max-len": 0,
7-
"strict": 0,
8-
"consistent-return": 1,
9-
"no-sequences": 0
10-
},
11-
12-
"globals": {
13-
"exports": true,
14-
"module": true,
15-
"require": true
16-
}
2+
"extends": "@segment/eslint-config/browser/legacy"
173
}

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1+
coverage
12
node_modules
2-
components
3-
build
4-
test/pid.txt

.travis.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

History.md renamed to HISTORY.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
vNEXT / ????-??-??
2+
==================
3+
4+
* Remove Duo support, add Browserify support
5+
* Switch from Travis CI to Circle CI
6+
* Modernize test harness
7+
* Various reorganizations/cleanups
8+
19
1.1.1 / 2016-05-23
210
==================
311

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2016 Segment.io, Inc. ([email protected])
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

Makefile

Lines changed: 66 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,81 @@
1-
#
2-
# Binaries.
3-
#
4-
5-
DUO = node_modules/.bin/duo
6-
DUOT = node_modules/.bin/duo-test
7-
ESLINT = node_modules/.bin/eslint
8-
9-
#
10-
# Files.
11-
#
12-
13-
SRCS_DIR = lib
14-
SRCS = $(shell find lib -type f -name "*.js")
15-
TESTS_DIR = test
16-
TESTS = test/index.js
17-
18-
#
19-
# Task arguments.
20-
#
21-
22-
browser ?= chrome
23-
24-
#
25-
# Chore tasks.
26-
#
27-
28-
# Install node dependencies.
1+
##
2+
# Binaries
3+
##
4+
5+
ESLINT := node_modules/.bin/eslint
6+
KARMA := node_modules/.bin/karma
7+
8+
##
9+
# Files
10+
##
11+
12+
LIBS = $(shell find lib -type f -name "*.js")
13+
TESTS = $(shell find test -type f -name "*.test.js")
14+
SUPPORT = $(wildcard karma.conf*.js)
15+
ALL_FILES = $(LIBS) $(TESTS) $(SUPPORT)
16+
17+
##
18+
# Program options/flags
19+
##
20+
21+
# A list of options to pass to Karma
22+
# Overriding this overwrites all options specified in this file (e.g. BROWSERS)
23+
KARMA_FLAGS ?=
24+
25+
# A list of Karma browser launchers to run
26+
# http://karma-runner.github.io/0.13/config/browsers.html
27+
BROWSERS ?=
28+
ifdef BROWSERS
29+
KARMA_FLAGS += --browsers $(BROWSERS)
30+
endif
31+
32+
ifdef CI
33+
KARMA_CONF ?= karma.conf.ci.js
34+
else
35+
KARMA_CONF ?= karma.conf.js
36+
endif
37+
38+
# Mocha flags.
39+
GREP ?= .
40+
41+
##
42+
# Tasks
43+
##
44+
45+
# Install node modules.
2946
node_modules: package.json $(wildcard node_modules/*/package.json)
3047
@npm install
48+
@touch $@
3149

32-
# Create the build directory.
33-
build:
34-
@mkdir -p build
50+
# Install dependencies.
51+
install: node_modules
3552

3653
# Remove temporary files and build artifacts.
3754
clean:
38-
@rm -rf *.log build
55+
rm -rf *.log coverage
3956
.PHONY: clean
4057

4158
# Remove temporary files, build artifacts, and vendor dependencies.
42-
distclean:
43-
@rm -rf components node_modules
59+
distclean: clean
60+
rm -rf node_modules
4461
.PHONY: distclean
4562

46-
#
47-
# Build tasks.
48-
#
49-
50-
# Build all integrations, tests, and dependencies together for testing.
51-
build/build.js: node_modules component.json $(SRCS) $(TESTS) | build
52-
@$(DUO) --development test/index.js > $@
53-
.DEFAULT_GOAL = build/build.js
54-
55-
#
56-
# Test tasks.
57-
#
63+
# Lint JavaScript source files.
64+
lint: install
65+
@$(ESLINT) $(ALL_FILES)
66+
.PHONY: lint
5867

59-
# Lint JavaScript source.
60-
lint: node_modules
61-
@$(ESLINT) $(wildcard lib/*.js test/index.js)
68+
# Attempt to fix linting errors.
69+
fmt: install
70+
@$(ESLINT) --fix $(ALL_FILES)
71+
.PHONY: fmt
6272

63-
# Test locally in PhantomJS.
64-
test: node_modules lint build/build.js
65-
@$(DUOT) phantomjs
66-
.PHONY: test
67-
68-
# Test locally in the browser.
69-
test-browser: node_modules lint build/build.js
70-
@$(DUOT) browser --commands "make build/build.js"
73+
# Run browser unit tests in a browser.
74+
test-browser: install
75+
@$(KARMA) start $(KARMA_FLAGS) $(KARMA_CONF)
7176
.PHONY: test-browser
7277

73-
# Test in Sauce Labs. Note that you must set the SAUCE_USERNAME and
74-
# SAUCE_ACCESS_KEY environment variables using your Sauce Labs credentials.
75-
test-sauce: node_modules build/build.js
76-
@$(DUOT) saucelabs -b $(browser)
77-
.PHONY: test-sauce
78+
# Default test target.
79+
test: lint test-browser
80+
.PHONY: test
81+
.DEFAULT_GOAL = test

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# analytics.js-integration
2+
3+
[![CircleCI](https://circleci.com/gh/segmentio/analytics.js-integration.svg?style=shield&circle-token=096975c79692a2267d9a92fd412b6b8bb7e3eb0a)](https://circleci.com/gh/segmentio/analytics.js-integration)
4+
[![Codecov](https://img.shields.io/codecov/c/github/segmentio/analytics.js-integration/master.svg?maxAge=2592000)](https://codecov.io/gh/segmentio/analytics.js-integration)
5+
6+
The base integration factory used to create custom analytics integrations for [Analytics.js](https://github.com/segmentio/analytics.js).
7+
8+
The factory returns a barebones integration that has no logic, so that we can share common pieces of logic—like queueing before an integration is ready, providing a way to default options, etc—in one place.
9+
10+
## Integrating with Segment
11+
12+
Interested in integrating your service with us? Check out our [Partners page](https://segment.com/partners/) for more details.
13+
14+
## Example
15+
16+
```js
17+
var integration = require('integration');
18+
19+
var Custom = integration('Custom Analytics')
20+
.global('_custom')
21+
.assumesPageview()
22+
.readyOnInitialize();
23+
24+
Custom.prototype.track = function (event, properties) {
25+
window._custom.push(['track', event, properties]);
26+
};
27+
```
28+
29+
## Facade
30+
31+
This library relies on [`segmentio/facade`](https://github.com/segmentio/facade) which is a helper that makes working with the input to [Analytics.js](https://github.com/segmentio/analytics.js) easier, by handling lots of common cases in one place.
32+
33+
## API
34+
35+
### integration(name)
36+
37+
Create a new `Integration` constructor with the given integration `name`. `name` is the key with which users can `initialize` the integration.
38+
39+
### .option(key, default)
40+
41+
Register a new option for the integration by `key`, with a `default` value.
42+
43+
### .mapping(key)
44+
45+
Add a new mapping option by `key`. The option will be an array that the user can pass in of `key -> value` mappings. This will also generated a `#KEY` method on the integration's prototype for easily accessing the mapping.
46+
47+
For example if your integration only supports a handful of events like `Signed Up` and `Completed Order`, you might create an mapping option called `events` that the user would pass in, like so:
48+
49+
```js
50+
var MyIntegration = Integration('MyIntegration')
51+
.mapping('events');
52+
```
53+
54+
Which means that when the integration is initialized, it would be passed a mapping of `events` to use, like so:
55+
56+
```js
57+
new MyIntegration({
58+
events: [
59+
{ key: 'Signed Up', value: 'Register' },
60+
{ key: 'Completed Order', value: 'Purchase' }
61+
]
62+
});
63+
```
64+
65+
Then later on, you can easily get all of the entries with a specific key, by calling `this.events(key)`. For example:
66+
67+
```js
68+
MyIntegration.prototype.track = function(track){
69+
var matches = this.events(track.event());
70+
each(matches, function(value){
71+
window._myglobal.push(value);
72+
});
73+
};
74+
```
75+
76+
### .global(key)
77+
78+
Register a new global variable `key` that the Integration uses. If this key already exists on `window` when `initialize` is called, it will return early, thus ensuring that setup logic and libraries aren't loaded twice.
79+
80+
### .assumesPageview()
81+
82+
Mark the `Integration` as assuming an initial pageview has happened when its Javascript library loads. This is important for integrations whose libraries assume a "pageview" in their interface as soon as the library loads, instead of exposing a `.page()` method or similar to call via Javascript.
83+
84+
This option changes the integration so that the very first call to `page` actually initializes the integration, ensuring that the pageviews aren't accidentally duplicated.
85+
86+
### .readyOnInitialize()
87+
88+
Mark the `Integration` as being ready to accept data after `initialize` is called. This is true of integrations that create queues in their snippets so that they can record data before their library has been downloaded.
89+
90+
### .readyOnLoad()
91+
92+
Mark the `Integration` as being ready to accept data after `load` is called. This is true for integrations that need to wait for their library to load on the page to start recording data.
93+
94+
### #initialize([page])
95+
96+
Initialize the integration. This is where the typical 3rd-party Javascript snippet logic should be. If the integration assumes an initial pageview, `initialize` will be called with the `page` method's arguments.
97+
98+
### #load([callback])
99+
100+
Load the integration's 3rd-party Javascript library, and `callback(err, e)`. The loading logic should be pulled out of the snippet from `initialize` and placed here.
101+
102+
### #identify(facade)
103+
104+
Identify the current user for the integration given an `Identify` [`facade`](https://github.com/segmentio/facade). See the [`identify` method docs](https://segment.io/docs/tracking-api/identify/) for more information.
105+
106+
### #group(facade)
107+
108+
Group the current account/organization/group/etc for the integration given an `Group` [`facade`](https://github.com/segmentio/facade). See the [`group` method docs](https://segment.io/docs/tracking-api/group/) for more information.
109+
110+
### #page(facade)
111+
112+
Transform a `Page` [`facade`](https://github.com/segmentio/facade) into a page view for the integration. See the [`page` method docs](https://segment.io/docs/tracking-api/page-and-screen/) for more information.
113+
114+
[Identify a user.](https://segment.io/docs/tracking-api/identify)
115+
116+
### #track(facade)
117+
118+
Track an event with the integration, given a `Track` [`facade`](https://github.com/segmentio/facade). See the [`track` method docs](https://segment.io/docs/tracking-api/track/) for more information.
119+
120+
### #alias(facade)
121+
122+
Alias two user identities given an `Alias` `facade`. See the [`alias` method docs](https://segment.io/docs/tracking-api/alias/) for more information.

0 commit comments

Comments
 (0)