Skip to content

Commit a804b8c

Browse files
authored
Add profitwell destination (#612)
* Add profitwell destination * cleanup
1 parent 3d20325 commit a804b8c

File tree

12 files changed

+378
-0
lines changed

12 files changed

+378
-0
lines changed

integrations/profitwell/.eslintrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 6
4+
},
5+
"env": {
6+
"browser": true
7+
},
8+
"extends": "@segment/eslint-config/browser/legacy"
9+
}

integrations/profitwell/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
coverage
2+
node_modules
3+
.idea

integrations/profitwell/HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
1.0.0 / 2019-05-10
2+
==================
3+
4+
* First stab at Profitwell DotJS

integrations/profitwell/LICENSE

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

integrations/profitwell/Makefile

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.
46+
node_modules: package.json $(wildcard node_modules/*/package.json)
47+
@npm install
48+
@touch $@
49+
50+
# Install dependencies.
51+
install: node_modules
52+
53+
# Remove temporary files and build artifacts.
54+
clean:
55+
rm -rf *.log coverage
56+
.PHONY: clean
57+
58+
# Remove temporary files, build artifacts, and vendor dependencies.
59+
distclean: clean
60+
rm -rf node_modules
61+
.PHONY: distclean
62+
63+
# Lint JavaScript source files.
64+
lint: install
65+
@$(ESLINT) $(ALL_FILES)
66+
.PHONY: lint
67+
68+
# Attempt to fix linting errors.
69+
fmt: install
70+
@$(ESLINT) --fix $(ALL_FILES)
71+
.PHONY: fmt
72+
73+
# Run browser unit tests in a browser.
74+
test-browser: install
75+
@$(KARMA) start $(KARMA_FLAGS) $(KARMA_CONF)
76+
77+
# Default test target.
78+
test: lint test-browser
79+
.PHONY: test
80+
.DEFAULT_GOAL = test

integrations/profitwell/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# analytics.js-integration-profitwell-dotjs
2+
3+
Profitwell DotJS integration for [Analytics.js][].
4+
5+
## License
6+
7+
Released under the [MIT license](LICENSE).
8+
9+
[Analytics.js]: https://segment.com/docs/libraries/analytics.js/
10+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../../karma.conf-ci.js');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('../../karma.conf');
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
'use strict';
2+
3+
var integration = require('@segment/analytics.js-integration');
4+
var Identify = require('segmentio-facade').Identify;
5+
6+
var ProfitWell = module.exports = integration('ProfitWell')
7+
.global('profitwell')
8+
.option('publicApiToken')
9+
.option('siteType', 'marketing')
10+
.tag('<script src="https://public.profitwell.com/js/profitwell.js?auth={{publicApiToken}}">');
11+
12+
ProfitWell.prototype.initialize = function() {
13+
window.profitwell = window.profitwell || function() {
14+
window.profitwell.q = window.profitwell.q || [];
15+
window.profitwell.q.push(arguments);
16+
};
17+
18+
var user = this.analytics.user();
19+
var traits = user.traits() || {};
20+
var id = new Identify({ traits: traits });
21+
var email = id.email();
22+
23+
window.profitwell('auth_token', this.options.publicApiToken);
24+
25+
if (email) {
26+
this.start(email);
27+
}
28+
29+
if (this.options.siteType === 'marketing') {
30+
this.start();
31+
}
32+
33+
this.load(this.ready);
34+
};
35+
36+
ProfitWell.prototype.identify = function(identify) {
37+
if (identify.email()) {
38+
this.start(identify.email());
39+
} else {
40+
this.start();
41+
}
42+
};
43+
44+
ProfitWell.prototype.start = function(email) {
45+
if (this.started) {
46+
return;
47+
}
48+
49+
var args = email ? { user_email: email } : {};
50+
window.profitwell('start', args);
51+
this.started = true;
52+
};
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"name": "@profitwell/analytics.js-integration",
3+
"description": "The Profitwell DotJS analytics.js integration.",
4+
"version": "1.0.1",
5+
"keywords": [
6+
"analytics.js",
7+
"analytics.js-integration",
8+
"segment",
9+
"profitwell"
10+
],
11+
"main": "lib/index.js",
12+
"scripts": {
13+
"test": "karma start",
14+
"test:ci": "karma start karma.conf-ci.js"
15+
},
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/ProfitWell/segment-dotjs"
19+
},
20+
"author": "",
21+
"license": "SEE LICENSE IN LICENSE",
22+
"bugs": {
23+
"url": "https://github.com/ProfitWell/segment-dotjs/issues"
24+
},
25+
"homepage": "https://github.com/ProfitWell/segment-dotjs#readme",
26+
"dependencies": {
27+
"@segment/analytics.js-integration": "^3.1.0",
28+
"segmentio-facade": "^3.1.0"
29+
},
30+
"devDependencies": {
31+
"@segment/analytics.js-core": "^3.0.0",
32+
"@segment/analytics.js-integration-tester": "^3.1.0",
33+
"@segment/clear-env": "^2.0.0",
34+
"@segment/eslint-config": "^3.1.1",
35+
"browserify": "^13.0.0",
36+
"browserify-istanbul": "^2.0.0",
37+
"eslint": "^2.9.0",
38+
"eslint-plugin-mocha": "^2.2.0",
39+
"eslint-plugin-require-path-exists": "^1.1.5",
40+
"istanbul": "^0.4.3",
41+
"karma": "1.3.0",
42+
"karma-browserify": "^5.0.4",
43+
"karma-chrome-launcher": "^2.2.0",
44+
"karma-coverage": "^1.0.0",
45+
"karma-junit-reporter": "^1.0.0",
46+
"karma-mocha": "1.0.1",
47+
"karma-phantomjs-launcher": "^1.0.0",
48+
"karma-sauce-launcher": "^1.0.0",
49+
"karma-spec-reporter": "0.0.26",
50+
"mocha": "^2.2.5",
51+
"npm-check": "^5.2.1",
52+
"phantomjs-prebuilt": "^2.1.7",
53+
"watchify": "^3.7.0"
54+
}
55+
}

0 commit comments

Comments
 (0)