Module: Card::Set::All::GoogleAnalytics::HtmlFormat

Extended by:
Card::Set::AbstractFormat
Defined in:
tmpsets/set/mod027-google_analytics/all/google_analytics.rb

Instance Method Summary collapse

Instance Method Details

#google_analytics_keyObject



19
20
21
# File 'tmpsets/set/mod027-google_analytics/all/google_analytics.rb', line 19

def google_analytics_key
  @google_analytics_key ||= Card.global_setting :google_analytics_key
end

#google_analytics_snippet_javascriptObject



36
37
38
39
40
41
42
43
44
45
# File 'tmpsets/set/mod027-google_analytics/all/google_analytics.rb', line 36

def google_analytics_snippet_javascript
  <<-JAVASCRIPT
    var _gaq = _gaq || [];#{"\n" + google_analytics_snippet_vars_string}
    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  JAVASCRIPT
end

#google_analytics_snippet_varsObject



23
24
25
26
# File 'tmpsets/set/mod027-google_analytics/all/google_analytics.rb', line 23

def google_analytics_snippet_vars
  [[:_setAccount, google_analytics_key],
   [:_trackPageview]]
end

#google_analytics_snippet_vars_stringObject



28
29
30
31
32
33
34
# File 'tmpsets/set/mod027-google_analytics/all/google_analytics.rb', line 28

def google_analytics_snippet_vars_string
  google_analytics_snippet_vars.map do |array|
    <<-JAVASCRIPT
    _gaq.push([#{array.map { |i| "'#{i}'" }.join ', '}]);
    JAVASCRIPT
  end.join
end

#views_in_headObject



10
11
12
# File 'tmpsets/set/mod027-google_analytics/all/google_analytics.rb', line 10

def views_in_head
  super << :google_analytics_snippet
end