Class: Jirafe::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/jirafe/tracker.rb

Class Method Summary collapse

Class Method Details

.js_pathObject



5
6
7
# File 'lib/jirafe/tracker.rb', line 5

def js_path
  [Jirafe.config.tracking_path, "jirafe.js"].join("/")
end

.js_tag(json_data = "{}", html_options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jirafe/tracker.rb', line 9

def js_tag(json_data = "{}", html_options = {})
  unless Jirafe.config.default?
    original_json_data = JSON.parse(json_data)
    json_data = { "baseUrl" => Jirafe.config.data_path }.merge(original_json_data).to_json
  end
  tag_id = html_options[:id] || "jirafe_analytics"
  <<-HTML
<script type='text/javascript' id='#{tag_id}'>
  var jirafe = #{json_data};
  (function(){
  var d=document,g=d.createElement('script'),s=d.getElementsByTagName('script')[0];
  g.type='text/javascript',g.defer=g.async=true;g.src=d.location.protocol+'//#{js_path}';
  s.parentNode.insertBefore(g, s);
  })();
</script>
  HTML
end