-
Notifications
You must be signed in to change notification settings - Fork 149
/
index.js
98 lines (82 loc) · 1.71 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict';
/**
* Module dependencies.
*/
var each = require('component-each');
var integration = require('@segment/analytics.js-integration');
var push = require('global-queue')('_mfq');
/**
* Expose `Mouseflow`.
*/
var Mouseflow = (module.exports = integration('Mouseflow')
.assumesPageview()
.global('_mfq')
.global('mouseflow')
.global('mouseflowHtmlDelay')
.option('apiKey', '')
.option('mouseflowHtmlDelay', 0)
.tag('<script src="//cdn.mouseflow.com/projects/{{ apiKey }}.js">'));
/**
* Initalize.
*
* @api public
*/
Mouseflow.prototype.initialize = function() {
window.mouseflowHtmlDelay = this.options.mouseflowHtmlDelay;
this.load(this.ready);
};
/**
* Loaded?
*
* @api private
* @return {boolean}
*/
Mouseflow.prototype.loaded = function() {
return !!window.mouseflow;
};
/**
* Page.
*
* http://mouseflow.zendesk.com/entries/22528817-Single-page-websites
*
* @api public
* @param {Page} page
*/
Mouseflow.prototype.page = function(page) {
push('newPageView', page.path());
};
/**
* Identify.
*
* http://mouseflow.zendesk.com/entries/24643603-Custom-Variables-Tagging
*
* @api public
* @param {Identify} identify
*/
Mouseflow.prototype.identify = function(identify) {
set(identify.traits());
};
/**
* Track.
*
* http://mouseflow.zendesk.com/entries/24643603-Custom-Variables-Tagging
*
* @api public
* @param {Track} track
*/
Mouseflow.prototype.track = function(track) {
var props = track.properties();
props.event = track.event();
set(props);
};
/**
* Push each key and value in the given `obj` onto the queue.
*
* @api private
* @param {Object} obj
*/
function set(obj) {
each(obj, function(key, value) {
push('setVariable', key, value);
});
}