segment_rails 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/segment_rails.rb +14 -0
- data/vendor/assets/javascripts/segment_rails.js +103 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 45a50ecd2866fc9b994f61252c91150fed6ce6ee
|
4
|
+
data.tar.gz: d4851fc9a646a1a9916310e13a9f6302de9d287a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b650898e6877a6b3310d8c96fec8498981d323128d3d212d6669d27bc4b7ae2136c3fd7a0bcc4c3a52a0978c68c3e12506d352a7587f257fa1be9111be2f4d57
|
7
|
+
data.tar.gz: c79720efcad610433a1fa7e178b0cd1bbbbfdaf75fe856b172ec3d5b6ad1e6a673c4c920eed0a6a15c13e5f79c69323937efcb2d1e4bf15643fbfacce7228d80
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module SegmentRails
|
2
|
+
module Rails
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
def track_event(event_name, properties={})
|
8
|
+
analytics = cookies[:analytics] ? JSON.parse(cookies[:analytics]) : {}
|
9
|
+
analytics[:uuid] = current_user.uuid if current_user
|
10
|
+
analytics[:events] ||= []
|
11
|
+
analytics[:events].push({ name: event_name, properties: properties})
|
12
|
+
cookies[:analytics] = JSON.dump(analytics)
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
(function() {
|
2
|
+
var monster = (function() {
|
3
|
+
/*!
|
4
|
+
* cookie-monster - a simple cookie library
|
5
|
+
* v0.3.0
|
6
|
+
* https://github.com/jgallen23/cookie-monster
|
7
|
+
* copyright Greg Allen 2014
|
8
|
+
* MIT License
|
9
|
+
*/
|
10
|
+
return {
|
11
|
+
set: function(name, value, days, path, secure) {
|
12
|
+
var date = new Date(),
|
13
|
+
expires = '',
|
14
|
+
type = typeof(value),
|
15
|
+
valueToUse = '',
|
16
|
+
secureFlag = '';
|
17
|
+
path = path || "/";
|
18
|
+
if (days) {
|
19
|
+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
20
|
+
expires = "; expires=" + date.toUTCString();
|
21
|
+
}
|
22
|
+
if (type === "object" && type !== "undefined") {
|
23
|
+
if(!("JSON" in window)) throw "Bummer, your browser doesn't support JSON parsing.";
|
24
|
+
valueToUse = encodeURIComponent(JSON.stringify({v:value}));
|
25
|
+
} else {
|
26
|
+
valueToUse = encodeURIComponent(value);
|
27
|
+
}
|
28
|
+
if (secure){
|
29
|
+
secureFlag = "; secure";
|
30
|
+
}
|
31
|
+
|
32
|
+
document.cookie = name + "=" + valueToUse + expires + "; path=" + path + secureFlag;
|
33
|
+
},
|
34
|
+
get: function(name) {
|
35
|
+
var nameEQ = name + "=",
|
36
|
+
ca = document.cookie.split(';'),
|
37
|
+
value = '',
|
38
|
+
firstChar = '',
|
39
|
+
parsed={};
|
40
|
+
for (var i = 0; i < ca.length; i++) {
|
41
|
+
var c = ca[i];
|
42
|
+
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
43
|
+
if (c.indexOf(nameEQ) === 0) {
|
44
|
+
value = decodeURIComponent(c.substring(nameEQ.length, c.length));
|
45
|
+
firstChar = value.substring(0, 1);
|
46
|
+
if(firstChar=="{"){
|
47
|
+
try {
|
48
|
+
parsed = JSON.parse(value);
|
49
|
+
if("v" in parsed) return parsed.v;
|
50
|
+
} catch(e) {
|
51
|
+
return value;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
if (value=="undefined") return undefined;
|
55
|
+
return value;
|
56
|
+
}
|
57
|
+
}
|
58
|
+
return null;
|
59
|
+
},
|
60
|
+
remove: function(name) {
|
61
|
+
this.set(name, "", -1);
|
62
|
+
},
|
63
|
+
increment: function(name, days) {
|
64
|
+
var value = this.get(name) || 0;
|
65
|
+
this.set(name, (parseInt(value, 10) + 1), days);
|
66
|
+
},
|
67
|
+
decrement: function(name, days) {
|
68
|
+
var value = this.get(name) || 0;
|
69
|
+
this.set(name, (parseInt(value, 10) - 1), days);
|
70
|
+
}
|
71
|
+
};
|
72
|
+
})();
|
73
|
+
|
74
|
+
function enableDebugMode() {
|
75
|
+
var options = window.location.search.substring(1);
|
76
|
+
if (options.match(/debug/i)) {
|
77
|
+
console.log(analytics.debug);
|
78
|
+
analytics.debug();
|
79
|
+
} else {
|
80
|
+
analytics.debug(false);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
|
84
|
+
function trackEvents() {
|
85
|
+
var to_track = JSON.parse(monster.get("analytics"));
|
86
|
+
if (!to_track) { return; }
|
87
|
+
|
88
|
+
if (to_track.uuid) {
|
89
|
+
analytics.identify(to_track.uuid);
|
90
|
+
}
|
91
|
+
if (to_track.events) {
|
92
|
+
to_track.events.forEach(function(evnt) {
|
93
|
+
analytics.track(evnt.name.replace(/\+/g, " "), evnt.properties);
|
94
|
+
});
|
95
|
+
}
|
96
|
+
monster.remove("analytics");
|
97
|
+
}
|
98
|
+
|
99
|
+
analytics.ready(function() {
|
100
|
+
enableDebugMode();
|
101
|
+
trackEvents();
|
102
|
+
});
|
103
|
+
})();
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: segment_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zinc
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-30 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Track events on the front end with segment!
|
14
|
+
email: hello@zincma.de
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/segment_rails.rb
|
20
|
+
- vendor/assets/javascripts/segment_rails.js
|
21
|
+
homepage: http://rubygems.org/gems/segment_rails
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.4.5
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Track events on the front end with segment!
|
45
|
+
test_files: []
|