Skip to content

Commit 9c591d3

Browse files
committed
Initial
1 parent 03fdb7f commit 9c591d3

File tree

7 files changed

+88
-157
lines changed

7 files changed

+88
-157
lines changed

Contributing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Contributing
22

3-
We're huge fans of open-source, and we absolutely love getting good contributions to **analytics.js**! Integrations are available to thousands of Segment customers and we have hundreds of integrations in already in our queue, so it's important that you do the following _before writing a pull request_.
3+
We're huge fans of open-source, and we absolutely love getting good contributions to **analytics.js**! Integrations are available to thousands of Segment customers and we have hundreds of integrations in already in our queue, so it's important that you do the following _before writing a pull request_.
44

55
1. Read about our integration options and apply to be a partner: https://segment.com/partners/
66
1. Hear from the Segment team before submitting your pull request.
@@ -12,7 +12,7 @@ To start, we'll get you set up with our development environment. All of our deve
1212
Then after forking **analytics.js-integrations** just `cd` into the folder and run `make`:
1313

1414
```bash
15-
$ cd analytics.js-integration-customerio
15+
$ cd analytics.js-integration-drift
1616
$ make
1717
```
1818

Readme.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# analytics.js-integration-customerio [![Build Status][ci-badge]][ci-link]
1+
# analytics.js-integration-drift [![Build Status][ci-badge]][ci-link]
22

3-
Customerio integration for [Analytics.js][].
3+
Drift integration for [Analytics.js][].
44

55
## License
66

77
Released under the [MIT license](License.md).
88

99

1010
[Analytics.js]: https://segment.com/docs/libraries/analytics.js/
11-
[ci-link]: https://circleci.com/gh/segment-integrations/analytics.js-integration-customerio
12-
[ci-badge]: https://circleci.com/gh/segment-integrations/analytics.js-integration-customerio.svg?style=svg
11+
[ci-link]: https://circleci.com/gh/segment-integrations/analytics.js-integration-drift
12+
[ci-badge]: https://circleci.com/gh/segment-integrations/analytics.js-integration-drift.svg?style=svg

component.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "analytics.js-integration-customerio",
3-
"repo": "segment-integrations/analytics.js-integration-customerio",
4-
"description": "The Customerio analytics.js integration.",
5-
"version": "1.0.4",
2+
"name": "analytics.js-integration-drift",
3+
"repo": "segment-integrations/analytics.js-integration-drift",
4+
"description": "The Drift analytics.js integration.",
5+
"version": "1.0.0",
66
"license": "MIT",
77
"main": "lib/index.js",
88
"dependencies": {

lib/index.js

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,45 @@
33
* Module dependencies.
44
*/
55

6-
var Identify = require('facade').Identify;
7-
var alias = require('alias');
86
var convertDates = require('convert-dates');
97
var integration = require('analytics.js-integration');
108

9+
var REFRESH_RATE = 300000;
10+
var timeHash = Math.ceil(new Date() / REFRESH_RATE) * REFRESH_RATE;
11+
1112
/**
12-
* Expose `Customerio` integration.
13+
* Expose `Driftt` integration.
1314
*/
1415

15-
var Customerio = module.exports = integration('Customer.io')
16-
.global('_cio')
17-
.option('siteId', '')
18-
.tag('<script id="cio-tracker" src="https://assets.customer.io/assets/track.js" data-site-id="{{ siteId }}">');
16+
var Driftt = module.exports = integration('Driftt')
17+
.global('driftt')
18+
.option('embedId', '')
19+
.tag('<script src="https://js.driftt.com/include/' + timeHash + '/{{ embedId }}.js">');
1920

2021
/**
2122
* Initialize.
2223
*
23-
* http://customer.io/docs/api/javascript.html
24-
*
2524
* @api public
2625
*/
2726

28-
Customerio.prototype.initialize = function() {
29-
window._cio = window._cio || [];
30-
/* eslint-disable */
31-
(function(){var a,b,c; a = function(f){return function(){window._cio.push([f].concat(Array.prototype.slice.call(arguments,0))); }; }; b = ['identify', 'track']; for (c = 0; c < b.length; c++) {window._cio[b[c]] = a(b[c]); } })();
32-
/* eslint-enable */
27+
Driftt.prototype.initialize = function() {
28+
var driftt;
29+
30+
driftt = window.drift = window.driftt = window.driftt || [];
31+
driftt.methods = ['identify', 'track', 'reset', 'debug', 'show', 'ping', 'page', 'hide', 'off', 'on'];
32+
driftt.factory = function(method) {
33+
return function() {
34+
var args;
35+
args = Array.prototype.slice.call(arguments);
36+
args.unshift(method);
37+
driftt.push(args);
38+
};
39+
};
40+
41+
driftt.methods.forEach(function(key) {
42+
driftt[key] = driftt.factory(key);
43+
});
44+
3345
this.load(this.ready);
3446
};
3547

@@ -40,66 +52,40 @@ Customerio.prototype.initialize = function() {
4052
* @return {boolean}
4153
*/
4254

43-
Customerio.prototype.loaded = function() {
44-
return !!(window._cio && window._cio.push !== Array.prototype.push);
55+
Driftt.prototype.loaded = function() {
56+
return window.driftt !== undefined;
4557
};
4658

4759
/**
4860
* Identify.
4961
*
50-
* http://customer.io/docs/api/javascript.html#section-Identify_customers
51-
*
5262
* @api public
5363
* @param {Identify} identify
5464
*/
5565

56-
Customerio.prototype.identify = function(identify) {
66+
Driftt.prototype.identify = function(identify) {
5767
if (!identify.userId()) return this.debug('user id required');
58-
var traits = identify.traits({ createdAt: 'created' });
59-
traits = alias(traits, { created: 'created_at' });
60-
traits = convertDates(traits, convertDate);
61-
window._cio.identify(traits);
62-
};
63-
64-
/**
65-
* Group.
66-
*
67-
* @api public
68-
* @param {Group} group
69-
*/
70-
71-
Customerio.prototype.group = function(group) {
72-
var traits = group.traits();
73-
var user = this.analytics.user();
74-
75-
traits = alias(traits, function(trait) {
76-
return 'Group ' + trait;
77-
});
78-
79-
this.identify(new Identify({
80-
userId: user.id(),
81-
traits: traits
82-
}));
68+
if (!identify.email()) return this.debug('email required');
69+
var traits = identify.traits();
70+
var id = identify.userId();
71+
delete traits.id;
72+
window.driftt.identify(id, traits);
8373
};
8474

8575
/**
8676
* Track.
8777
*
88-
* http://customer.io/docs/api/javascript.html#section-Track_a_custom_event
89-
*
9078
* @api public
9179
* @param {Track} track
9280
*/
9381

94-
Customerio.prototype.track = function(track) {
82+
Driftt.prototype.track = function(track) {
9583
var properties = track.properties();
9684
properties = convertDates(properties, convertDate);
97-
window._cio.track(track.event(), properties);
85+
window.driftt.track(track.event(), properties);
9886
};
9987

10088
/**
101-
* Convert a date to the format Customer.io supports.
102-
*
10389
* @api private
10490
* @param {Date} date
10591
* @return {number}
@@ -108,3 +94,7 @@ Customerio.prototype.track = function(track) {
10894
function convertDate(date) {
10995
return Math.floor(date.getTime() / 1000);
11096
}
97+
98+
Driftt.prototype.page = function(page) {
99+
window.driftt.page(page.name());
100+
};

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "analytics.js-integration-customerio",
3-
"description": "The Customerio analytics.js integration.",
2+
"name": "analytics.js-integration-drift",
3+
"description": "The Drift analytics.js integration.",
44
"author": "Segment <[email protected]>",
55
"license": "MIT",
66
"main": "lib/index.js",
@@ -12,13 +12,13 @@
1212
"npm": ">=2.7.0"
1313
},
1414
"repository": {
15-
"url": "https://github.com/segment-integrations/analytics.js-integration-customerio.git",
15+
"url": "https://github.com/segment-integrations/analytics.js-integration-drift.git",
1616
"type": "git"
1717
},
1818
"bugs": {
19-
"url": "https://github.com/segment-integrations/analytics.js-integration-customerio/issues"
19+
"url": "https://github.com/segment-integrations/analytics.js-integration-drift/issues"
2020
},
21-
"homepage": "https://segment.com/docs/integrations/customerio/",
21+
"homepage": "https://segment.com/docs/integrations/drift/",
2222
"dependencies": {},
2323
"devDependencies": {
2424
"duo": "0.12.x",

test/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
<html>
33
<head>
44
<title>integrations tests</title>
5-
<link rel="stylesheet" href="/node_modules/mocha/mocha.css">
5+
<link rel="stylesheet" href="../node_modules/mocha/mocha.css">
66
</head>
77
<body>
88
<div id="mocha"></div>
9-
<script src="/saucelabs.js"></script>
10-
<script src="/node_modules/mocha/mocha.js"></script>
9+
<script src="saucelabs.js"></script>
10+
<script src="../node_modules/mocha/mocha.js"></script>
1111
<script>
1212
mocha.setup({
1313
ui: 'bdd',
@@ -31,6 +31,6 @@
3131
}
3232
};
3333
</script>
34-
<script src="/build.js"></script>
34+
<script src="../build.js"></script>
3535
</body>
3636
</html>

0 commit comments

Comments
 (0)