gsiener-analytical 2.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +56 -0
- data/Guardfile +8 -0
- data/LICENSE +20 -0
- data/README.rdoc +117 -0
- data/Rakefile +42 -0
- data/VERSION +1 -0
- data/analytical.gemspec +183 -0
- data/example/.gitignore +4 -0
- data/example/Gemfile +27 -0
- data/example/Gemfile.lock +80 -0
- data/example/README +244 -0
- data/example/Rakefile +10 -0
- data/example/app/controllers/application_controller.rb +6 -0
- data/example/app/controllers/page_controller.rb +18 -0
- data/example/app/helpers/application_helper.rb +2 -0
- data/example/app/helpers/page_helper.rb +2 -0
- data/example/app/views/layouts/application.html.erb +17 -0
- data/example/app/views/page/index.html.erb +6 -0
- data/example/app/views/page/test_a.html.erb +11 -0
- data/example/app/views/page/test_b.html.erb +7 -0
- data/example/config/analytical.yml +30 -0
- data/example/config/application.rb +46 -0
- data/example/config/boot.rb +6 -0
- data/example/config/database.yml +22 -0
- data/example/config/environment.rb +7 -0
- data/example/config/environments/development.rb +21 -0
- data/example/config/environments/production.rb +42 -0
- data/example/config/environments/test.rb +32 -0
- data/example/config/initializers/backtrace_silencers.rb +7 -0
- data/example/config/initializers/inflections.rb +10 -0
- data/example/config/initializers/mime_types.rb +5 -0
- data/example/config/initializers/secret_token.rb +7 -0
- data/example/config/initializers/session_store.rb +8 -0
- data/example/config/locales/en.yml +5 -0
- data/example/config/routes.rb +63 -0
- data/example/config.ru +4 -0
- data/example/db/seeds.rb +7 -0
- data/example/doc/README_FOR_APP +2 -0
- data/example/lib/tasks/.gitkeep +0 -0
- data/example/public/404.html +26 -0
- data/example/public/422.html +26 -0
- data/example/public/500.html +26 -0
- data/example/public/favicon.ico +0 -0
- data/example/public/images/rails.png +0 -0
- data/example/public/javascripts/application.js +2 -0
- data/example/public/javascripts/controls.js +965 -0
- data/example/public/javascripts/dragdrop.js +974 -0
- data/example/public/javascripts/effects.js +1123 -0
- data/example/public/javascripts/prototype.js +4874 -0
- data/example/public/javascripts/rails.js +118 -0
- data/example/public/robots.txt +5 -0
- data/example/public/stylesheets/.gitkeep +0 -0
- data/example/script/rails +9 -0
- data/example/test/functional/page_controller_test.rb +19 -0
- data/example/test/performance/browsing_test.rb +9 -0
- data/example/test/test_helper.rb +13 -0
- data/example/test/unit/helpers/page_helper_test.rb +4 -0
- data/example/vendor/plugins/.gitkeep +0 -0
- data/gsiener-analytical.gemspec +167 -0
- data/lib/analytical/api.rb +117 -0
- data/lib/analytical/bot_detector.rb +46 -0
- data/lib/analytical/command_store.rb +19 -0
- data/lib/analytical/modules/adroll.rb +38 -0
- data/lib/analytical/modules/adwords.rb +80 -0
- data/lib/analytical/modules/base.rb +83 -0
- data/lib/analytical/modules/chartbeat.rb +49 -0
- data/lib/analytical/modules/click_tale.rb +47 -0
- data/lib/analytical/modules/clicky.rb +49 -0
- data/lib/analytical/modules/comscore.rb +25 -0
- data/lib/analytical/modules/console.rb +82 -0
- data/lib/analytical/modules/crazy_egg.rb +24 -0
- data/lib/analytical/modules/google.rb +44 -0
- data/lib/analytical/modules/google_optimizer.rb +62 -0
- data/lib/analytical/modules/hubspot.rb +28 -0
- data/lib/analytical/modules/kiss_metrics.rb +54 -0
- data/lib/analytical/modules/loopfuse.rb +30 -0
- data/lib/analytical/modules/microsoft_ads.rb +58 -0
- data/lib/analytical/modules/mixpanel.rb +56 -0
- data/lib/analytical/modules/optimizely.rb +23 -0
- data/lib/analytical/modules/performancing.rb +34 -0
- data/lib/analytical/modules/quantcast.rb +49 -0
- data/lib/analytical/modules/reinvigorate.rb +48 -0
- data/lib/analytical/modules/totango.rb +49 -0
- data/lib/analytical/session_command_store.rb +39 -0
- data/lib/analytical.rb +56 -0
- data/rails/init.rb +1 -0
- data/spec/analytical/api_spec.rb +157 -0
- data/spec/analytical/bot_detector_spec.rb +24 -0
- data/spec/analytical/command_store_spec.rb +36 -0
- data/spec/analytical/modules/adroll_spec.rb +27 -0
- data/spec/analytical/modules/adwords_spec.rb +76 -0
- data/spec/analytical/modules/base_spec.rb +138 -0
- data/spec/analytical/modules/chartbeat_spec.rb +26 -0
- data/spec/analytical/modules/clicky_spec.rb +50 -0
- data/spec/analytical/modules/comscore_spec.rb +27 -0
- data/spec/analytical/modules/google_spec.rb +45 -0
- data/spec/analytical/modules/kiss_metrics_spec.rb +51 -0
- data/spec/analytical/modules/mixpanel_spec.rb +71 -0
- data/spec/analytical/modules/optimizely_spec.rb +26 -0
- data/spec/analytical/modules/quantcast.rb +26 -0
- data/spec/analytical/modules/reinvigorate_spec.rb +35 -0
- data/spec/analytical/session_command_store_spec.rb +50 -0
- data/spec/analytical_spec.rb +79 -0
- data/spec/config/analytical.yml +9 -0
- data/spec/spec.opts +5 -0
- data/spec/spec_helper.rb +19 -0
- metadata +294 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Modules
|
3
|
+
module Base
|
4
|
+
attr_reader :tracking_command_location, :options, :initialized
|
5
|
+
attr_reader :command_store
|
6
|
+
|
7
|
+
def initialize(_options={})
|
8
|
+
@options = _options
|
9
|
+
@tracking_command_location = :body_prepend
|
10
|
+
@initialized = false
|
11
|
+
@command_store = @options[:session_store] || Analytical::CommandStore.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def protocol
|
15
|
+
@options[:ssl] ? 'https' : 'http'
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# The core methods that most analytics services implement are listed below.
|
20
|
+
# Modules will ignore any calls that they don't respond to, allowing them to
|
21
|
+
# only partially implement this basic template (or implement their own arbitrary custom methods)
|
22
|
+
#
|
23
|
+
|
24
|
+
# This is used to record page-view events, where you want to pass a URL to an analytics service
|
25
|
+
# def track(*args)
|
26
|
+
|
27
|
+
# Identify provides a unique identifier to an analytics service to keep track of the current user
|
28
|
+
# id should be a unique string (depending on which service you use), and some services also
|
29
|
+
# make use of a data hash as a second parameters, containing :email=>'test@test.com', for instance
|
30
|
+
# def identify(id, *args)
|
31
|
+
|
32
|
+
# Event is meant to track important funnel conversions in your app, or other important events
|
33
|
+
# that you want to inform a funnel analytics service about. You can pass optional data to this method as well.
|
34
|
+
# def event(name, *args)
|
35
|
+
|
36
|
+
# Set passes some data to the analytics service that should be attached to the current user identity
|
37
|
+
# It can be used to set AB-testing choices and other unique data, so that split testing results can be
|
38
|
+
# reported by an analytics service
|
39
|
+
# def set(data)
|
40
|
+
|
41
|
+
# This method generates the initialization javascript that an analytics service uses to track your site
|
42
|
+
# def init_javascript(location)
|
43
|
+
|
44
|
+
def queue(*args)
|
45
|
+
return if @options[:ignore_duplicates] && @command_store.include?(args)
|
46
|
+
if args.first==:identify
|
47
|
+
@command_store.unshift args
|
48
|
+
else
|
49
|
+
@command_store << args
|
50
|
+
end
|
51
|
+
end
|
52
|
+
def process_queued_commands
|
53
|
+
command_strings = @command_store.collect do |c|
|
54
|
+
send(*c) if respond_to?(c.first)
|
55
|
+
end.compact
|
56
|
+
@command_store.flush
|
57
|
+
command_strings
|
58
|
+
end
|
59
|
+
|
60
|
+
def init_location?(location)
|
61
|
+
if @tracking_command_location.is_a?(Array)
|
62
|
+
@tracking_command_location.map { |item|item.to_sym }.include?(location.to_sym)
|
63
|
+
else
|
64
|
+
@tracking_command_location.to_sym == location.to_sym
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def init_location(location, &block)
|
69
|
+
if init_location?(location)
|
70
|
+
@initialized = true
|
71
|
+
if block_given?
|
72
|
+
yield
|
73
|
+
else
|
74
|
+
''
|
75
|
+
end
|
76
|
+
else
|
77
|
+
''
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Modules
|
3
|
+
class Chartbeat
|
4
|
+
include Analytical::Modules::Base
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = [:head_prepend, :body_append]
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
case location.to_sym
|
14
|
+
when :head_prepend
|
15
|
+
js = <<-HTML
|
16
|
+
<!-- Analytical Head Init: Chartbeat -->
|
17
|
+
<script type="text/javascript">var _sf_startpt=(new Date()).getTime();</script>
|
18
|
+
HTML
|
19
|
+
js
|
20
|
+
when :body_append
|
21
|
+
js = <<-HTML
|
22
|
+
<!-- Analytical Body Init: Chartbeat -->
|
23
|
+
<script type="text/javascript">
|
24
|
+
var _sf_async_config={uid:#{options[:key]}, domain:"#{options[:domain]}"};
|
25
|
+
(function(){
|
26
|
+
function loadChartbeat() {
|
27
|
+
window._sf_endpt=(new Date()).getTime();
|
28
|
+
var e = document.createElement('script');
|
29
|
+
e.setAttribute('language', 'javascript');
|
30
|
+
e.setAttribute('type', 'text/javascript');
|
31
|
+
e.setAttribute('src',
|
32
|
+
(("https:" == document.location.protocol) ? "https://s3.amazonaws.com/" : "http://") +
|
33
|
+
"static.chartbeat.com/js/chartbeat.js");
|
34
|
+
document.body.appendChild(e);
|
35
|
+
}
|
36
|
+
var oldonload = window.onload;
|
37
|
+
window.onload = (typeof window.onload != 'function') ?
|
38
|
+
loadChartbeat : function() { oldonload(); loadChartbeat(); };
|
39
|
+
})();
|
40
|
+
</script>
|
41
|
+
HTML
|
42
|
+
js
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Modules
|
3
|
+
class ClickTale
|
4
|
+
include Analytical::Modules::Base
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = [:body_prepend, :body_append]
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
case location.to_sym
|
14
|
+
when :body_prepend
|
15
|
+
js = <<-HTML
|
16
|
+
<!-- Analytical Init: ClickTale Top part -->
|
17
|
+
<script type="text/javascript">
|
18
|
+
var WRInitTime=(new Date()).getTime();
|
19
|
+
</script>
|
20
|
+
<!-- ClickTale end of Top part -->
|
21
|
+
HTML
|
22
|
+
js
|
23
|
+
when :body_append
|
24
|
+
js = <<-HTML
|
25
|
+
<!-- Analytical Init: ClickTale Bottom part -->
|
26
|
+
<div id="ClickTaleDiv" style="display: none;"></div>
|
27
|
+
<script type='text/javascript'>
|
28
|
+
document.write(unescape("%3Cscript%20src='"+
|
29
|
+
(document.location.protocol=='https:'?
|
30
|
+
'https://clicktale.pantherssl.com/':
|
31
|
+
'http://s.clicktale.net/')+
|
32
|
+
"WRb6.js'%20type='text/javascript'%3E%3C/script%3E"));
|
33
|
+
</script>
|
34
|
+
<script type="text/javascript">
|
35
|
+
var ClickTaleSSL=1;
|
36
|
+
if(typeof ClickTale=='function') ClickTale(#{@options[:project_id]},#{@options[:site_traffic]},"www");
|
37
|
+
</script>
|
38
|
+
<!-- ClickTale end of Bottom part -->
|
39
|
+
HTML
|
40
|
+
js
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Modules
|
3
|
+
class Clicky
|
4
|
+
include Analytical::Modules::Base
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = :body_append
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
js = <<-HTML
|
14
|
+
<!-- Analytical Init: Clicky -->
|
15
|
+
<script src="#{protocol}://static.getclicky.com/js" type="text/javascript"></script>
|
16
|
+
<script type="text/javascript">clicky.init('#{@options[:key]}');</script>
|
17
|
+
<noscript><p><img alt="Clicky" width="1" height="1" src="#{protocol}://in.getclicky.com/#{@options[:key]}ns.gif" /></p></noscript>
|
18
|
+
HTML
|
19
|
+
|
20
|
+
identify_commands = []
|
21
|
+
@command_store.commands.each do |c|
|
22
|
+
if c[0] == :identify
|
23
|
+
identify_commands << identify(*c[1..-1])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
js = identify_commands.join("\n") + "\n" + js
|
27
|
+
@command_store.commands = @command_store.commands.delete_if {|c| c[0] == :identify }
|
28
|
+
|
29
|
+
js
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def track(*args)
|
34
|
+
"clicky.log(\"#{args.first}\");"
|
35
|
+
end
|
36
|
+
|
37
|
+
def identify(id, *args)
|
38
|
+
data = { :id=>id }.merge(args.first || {})
|
39
|
+
code = <<-HTML
|
40
|
+
<script type='text/javascript'>
|
41
|
+
var clicky_custom_session = #{data.to_json};
|
42
|
+
</script>
|
43
|
+
HTML
|
44
|
+
code
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Modules
|
3
|
+
class Comscore
|
4
|
+
include Analytical::Modules::Base
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = :head_append
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
js = <<-HTML
|
14
|
+
<!-- Analytical Init: comScore -->
|
15
|
+
<script>document.write(unescape("%3Cscript src='" + (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js' %3E%3C/script%3E"));</script>
|
16
|
+
<script>COMSCORE.beacon({c1:2, c2:#{options[:key]}, c3:"", c4:"", c5:"", c6:"", c15:""});</script>
|
17
|
+
<noscript><img src="http://b.scorecardresearch.com/p?c1=2&c2=#{options[:key]}&c3=&c4=&c5=&c6=&c15=&cj=1" /></noscript>
|
18
|
+
HTML
|
19
|
+
js
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Modules
|
3
|
+
class Console
|
4
|
+
include Analytical::Modules::Base
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = :body_append
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
js = <<-HTML
|
14
|
+
<!-- Analytical Init: Console -->
|
15
|
+
<script type="text/javascript">
|
16
|
+
if(typeof(console) !== 'undefined' && console != null) {
|
17
|
+
console.log('Analytical Init: Console');
|
18
|
+
}
|
19
|
+
</script>
|
20
|
+
HTML
|
21
|
+
js
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def track(*args)
|
26
|
+
check_for_console <<-HERE
|
27
|
+
console.log("Analytical Track: "+"#{escape args.first}");
|
28
|
+
HERE
|
29
|
+
end
|
30
|
+
|
31
|
+
def identify(id, *args)
|
32
|
+
data = args.first || {}
|
33
|
+
check_for_console <<-HERE
|
34
|
+
console.log("Analytical Identify: "+"#{escape id}");
|
35
|
+
console.log(#{data.to_json});
|
36
|
+
HERE
|
37
|
+
end
|
38
|
+
|
39
|
+
def event(name, *args)
|
40
|
+
data = args.first || {}
|
41
|
+
check_for_console <<-HERE
|
42
|
+
console.log("Analytical Event: "+"#{escape name}");
|
43
|
+
console.log(#{data.to_json});
|
44
|
+
HERE
|
45
|
+
end
|
46
|
+
|
47
|
+
def set(data)
|
48
|
+
check_for_console <<-HERE
|
49
|
+
console.log("Analytical Set: ");
|
50
|
+
console.log(#{data.to_json});
|
51
|
+
HERE
|
52
|
+
end
|
53
|
+
|
54
|
+
def alias_identity(old_identity,new_identity)
|
55
|
+
check_for_console <<-HERE
|
56
|
+
console.log("Analytical Alias: #{old_identity} => #{new_identity}");
|
57
|
+
HERE
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
CONSOLE_JS_ESCAPE_MAP = {
|
63
|
+
'\\' => '\\\\',
|
64
|
+
'</' => '<\/',
|
65
|
+
"\r\n" => '\n',
|
66
|
+
"\n" => '\n',
|
67
|
+
"\r" => '\n',
|
68
|
+
'"' => '\\"',
|
69
|
+
"'" => "\\'"
|
70
|
+
} unless defined?(CONSOLE_JS_ESCAPE_MAP)
|
71
|
+
|
72
|
+
def escape(js)
|
73
|
+
js.to_s.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { CONSOLE_JS_ESCAPE_MAP[$1] }
|
74
|
+
end
|
75
|
+
|
76
|
+
def check_for_console(data)
|
77
|
+
"if(typeof(console) !== 'undefined' && console != null) { #{data} }"
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Modules
|
3
|
+
class CrazyEgg
|
4
|
+
include Analytical::Modules::Base
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = :body_append
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
code_url = "#{options[:key].to_s[0,4]}/#{options[:key].to_s[4,4]}"
|
14
|
+
js = <<-HTML
|
15
|
+
<!-- Analytical Init: CrazyEgg -->
|
16
|
+
<script type="text/javascript" src="#{protocol}://s3.amazonaws.com/new.cetrk.com/pages/scripts/#{code_url}.js"> </script>
|
17
|
+
HTML
|
18
|
+
js
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Modules
|
3
|
+
class Google
|
4
|
+
include Analytical::Modules::Base
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = :head_append
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
js = <<-HTML
|
14
|
+
<!-- Analytical Init: Google -->
|
15
|
+
<script type="text/javascript">
|
16
|
+
var _gaq = _gaq || [];
|
17
|
+
_gaq.push(['_setAccount', '#{options[:key]}']);
|
18
|
+
_gaq.push(['_setDomainName', '#{options[:domain]}']);
|
19
|
+
#{"_gaq.push(['_setAllowLinker', true]);" if options[:allow_linker]}
|
20
|
+
_gaq.push(['_trackPageview']);
|
21
|
+
(function() {
|
22
|
+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
23
|
+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
24
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
25
|
+
})();
|
26
|
+
</script>
|
27
|
+
HTML
|
28
|
+
js
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def track(*args)
|
33
|
+
"_gaq.push(['_trackPageview'#{args.empty? ? ']' : ', "' + args.first + '"]'});"
|
34
|
+
end
|
35
|
+
|
36
|
+
def event(name, *args)
|
37
|
+
data = args.first || nil
|
38
|
+
data_string = data ? ", '#{data.to_json}'" : ""
|
39
|
+
"_gaq.push(['_trackEvent', \"Event\", \"#{name}\"" + data_string + "]);"
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Modules
|
3
|
+
class GoogleOptimizer
|
4
|
+
include Analytical::Modules::Base
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = :head_prepend
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
js = <<-HTML
|
14
|
+
<!-- Analytical Init: Google Website Optimizer Control Script -->
|
15
|
+
<script>
|
16
|
+
function utmx_section(){}function utmx(){}
|
17
|
+
(function(){var k='#{options[:key]}',d=document,l=d.location,c=d.cookie;function f(n){
|
18
|
+
if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.indexOf(';',i);return c.substring(i+n.
|
19
|
+
length+1,j<0?c.length:j)}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;
|
20
|
+
d.write('<sc'+'ript src="'+
|
21
|
+
'http'+(l.protocol=='https:'?'s://ssl':'://www')+'.google-analytics.com'
|
22
|
+
+'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='
|
23
|
+
+new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+
|
24
|
+
'" type="text/javascript" charset="utf-8"></sc'+'ript>')})();
|
25
|
+
</script>
|
26
|
+
<!-- End of Google Website Optimizer Control Script -->
|
27
|
+
<!-- Analytical Init: Google Website Optimizer Tracking Script -->
|
28
|
+
<script type="text/javascript">
|
29
|
+
if(typeof(_gat)!='object')document.write('<sc'+'ript src="http'+
|
30
|
+
(document.location.protocol=='https:'?'s://ssl':'://www')+
|
31
|
+
'.google-analytics.com/ga.js"></sc'+'ript>')</script>
|
32
|
+
<script type="text/javascript">
|
33
|
+
try {
|
34
|
+
var gwoTracker=_gat._getTracker("#{options[:account]}");
|
35
|
+
gwoTracker._trackPageview("/#{options[:key]}/test");
|
36
|
+
}catch(err){}</script>
|
37
|
+
<!-- End of Google Website Optimizer Tracking Script -->
|
38
|
+
HTML
|
39
|
+
js
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def conversion(*args)
|
44
|
+
js = <<-HTML
|
45
|
+
<!-- Analytical Init: Google Website Optimizer Conversion Script -->
|
46
|
+
<script type="text/javascript">
|
47
|
+
if(typeof(_gat)!='object')document.write('<sc'+'ript src="http'+
|
48
|
+
(document.location.protocol=='https:'?'s://ssl':'://www')+
|
49
|
+
'.google-analytics.com/ga.js"></sc'+'ript>')</script>
|
50
|
+
<script type="text/javascript">
|
51
|
+
try {
|
52
|
+
var gwoTracker=_gat._getTracker("#{options[:account]}");
|
53
|
+
gwoTracker._trackPageview("/#{options[:key]}/goal");
|
54
|
+
}catch(err){}</script>
|
55
|
+
<!-- End of Google Website Optimizer Conversion Script -->
|
56
|
+
HTML
|
57
|
+
js
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Modules
|
3
|
+
class Hubspot
|
4
|
+
include Analytical::Modules::Base
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = :body_append
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
js = <<-HTML
|
14
|
+
<!-- Analytical Init: Hubspot -->
|
15
|
+
<script type="text/javascript" language="javascript">
|
16
|
+
var hs_portalid=#{options[:portal_id]};
|
17
|
+
var hs_salog_version = "2.00";
|
18
|
+
var hs_ppa = "#{options[:domain]}";
|
19
|
+
document.write(unescape("%3Cscript src='" + document.location.protocol + "//" + hs_ppa + "/salog.js.aspx' type='text/javascript'%3E%3C/script%3E"));
|
20
|
+
</script>
|
21
|
+
HTML
|
22
|
+
js
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Modules
|
3
|
+
class KissMetrics
|
4
|
+
include Analytical::Modules::Base
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = :body_prepend
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
js = <<-HTML
|
14
|
+
<!-- Analytical Init: KissMetrics -->
|
15
|
+
<script type="text/javascript">
|
16
|
+
var _kmq = _kmq || [];
|
17
|
+
function _kms(u){
|
18
|
+
setTimeout(function(){
|
19
|
+
var s = document.createElement('script'); var f = document.getElementsByTagName('script')[0]; s.type = 'text/javascript'; s.async = true;
|
20
|
+
s.src = u; f.parentNode.insertBefore(s, f);
|
21
|
+
}, 1);
|
22
|
+
}
|
23
|
+
_kms('//i.kissmetrics.com/i.js');_kms('#{options[:js_url_key]}');
|
24
|
+
</script>
|
25
|
+
<script type="text/javascript">
|
26
|
+
_kmq.push(['pageView']);
|
27
|
+
</script>
|
28
|
+
HTML
|
29
|
+
js
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def identify(id, *args)
|
34
|
+
data = args.first || {}
|
35
|
+
"_kmq.push([\"identify\", \"#{data[:email]}\"]);"
|
36
|
+
end
|
37
|
+
|
38
|
+
def event(name, *args)
|
39
|
+
data = args.first || {}
|
40
|
+
"_kmq.push([\"record\", \"#{name}\", #{data.to_json}]);"
|
41
|
+
end
|
42
|
+
|
43
|
+
def set(data)
|
44
|
+
return '' if data.blank?
|
45
|
+
"_kmq.push([\"set\", #{data.to_json}]);"
|
46
|
+
end
|
47
|
+
|
48
|
+
def alias_identity(old_identity, new_identity)
|
49
|
+
"_kmq.push([\"alias\", \"#{old_identity}\", \"#{new_identity}\"]);"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Modules
|
3
|
+
class Loopfuse
|
4
|
+
include Analytical::Modules::Base
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = :body_append
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
js = <<-HTML
|
14
|
+
<!-- Analytical Init: LOOPFUSE TRACKING -->
|
15
|
+
<script type="text/javascript">
|
16
|
+
var LFHost = (("https:" == document.location.protocol) ? "https://" : "http://");
|
17
|
+
document.write(unescape("%3Cscript src='" + LFHost + "lfov.net/webrecorder/js/listen.js' type='text/javascript'%3E%3C/script%3E"));
|
18
|
+
</script>
|
19
|
+
<script type="text/javascript">
|
20
|
+
_lf_cid = "#{options[:cid]}";
|
21
|
+
_lf_remora();
|
22
|
+
</script>
|
23
|
+
<!-- END: LOOPFUSE TRACKING -->
|
24
|
+
HTML
|
25
|
+
js
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Analytical
|
2
|
+
module Modules
|
3
|
+
class MicrosoftAds
|
4
|
+
include Analytical::Modules::Base
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
super
|
8
|
+
@tracking_command_location = :body_append
|
9
|
+
end
|
10
|
+
|
11
|
+
def init_javascript(location)
|
12
|
+
init_location(location) do
|
13
|
+
@initializing = true
|
14
|
+
html = "<!-- Analytical Init: Microsoft Ads -->\n"
|
15
|
+
event_commands = []
|
16
|
+
@command_store.commands.each do |c|
|
17
|
+
if c[0] == :event
|
18
|
+
event_commands << event(*c[1..-1])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
html += event_commands.join("\n")
|
22
|
+
@command_store.commands = @command_store.commands.delete_if {|c| c[0] == :event }
|
23
|
+
@initializing = false
|
24
|
+
|
25
|
+
html
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# Define conversion events in analytical.yml like:
|
31
|
+
#
|
32
|
+
# microsoft_ads:
|
33
|
+
# 'Some Event':
|
34
|
+
# id: 55555555-6666-7777-8888-111111111111
|
35
|
+
def event(name, *args)
|
36
|
+
return '' unless @initializing
|
37
|
+
|
38
|
+
data = args.first || {}
|
39
|
+
if conversion = options[name.to_sym]
|
40
|
+
conversion.symbolize_keys!
|
41
|
+
js = <<-HTML
|
42
|
+
<script type="text/javascript">if (!window.mstag) mstag = {loadTag : function(){},time : (new Date()).getTime()};</script>
|
43
|
+
<script id="mstag_tops" type="text/javascript" src="//flex.atdmt.com/mstag/site/#{conversion[:id]}/mstag.js"></script>
|
44
|
+
<script type="text/javascript"> mstag.loadTag("conversion", {cp:"5050",dedup:"1"})</script>
|
45
|
+
<noscript>
|
46
|
+
<iframe src="//flex.atdmt.com/mstag/tag/#{conversion[:id]}/conversion.html?cp=5050&dedup=1" frameborder="0" scrolling="no" width="1" height="1" style="visibility:hidden; display:none"></iframe>
|
47
|
+
</noscript>
|
48
|
+
HTML
|
49
|
+
js
|
50
|
+
else
|
51
|
+
"<!-- No Microsoft Ads Conversion for: #{name} -->"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|