Module: Awestruct::Extensions::GoogleAnalytics
- Defined in:
- lib/awestruct/extensions/google_analytics.rb
Instance Method Summary collapse
- #google_analytics(options = {}) ⇒ Object
- #google_analytics_async ⇒ Object
- #google_analytics_universal(options = {}) ⇒ Object
Instance Method Details
#google_analytics(options = {}) ⇒ Object
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 |
# File 'lib/awestruct/extensions/google_analytics.rb', line 22 def google_analytics(={}) = defaults() html = '' html += %Q(<script type="text/javascript">\n) html += %Q(var _gaq = _gaq || [];\n) html += %Q(_gaq.push(['_setAccount','#{[:account]}']);\n) html += %Q(_gaq.push(['_gat._anonymizeIp']);\n) if [:anonymizeIp] html += %Q(_gaq.push(['_trackPageview']);\n) html += %Q(setTimeout("_gaq.push(['_trackEvent','#{[:bounceTime]}_seconds','read'])", #{[:bounceTime]}000);\n) if [:bounceTime] html += %Q(_gaq.push(['_require', 'inpage_linkid', '//www.google-analytics.com/plugins/ga/inpage_linkid.js']);\n) if [:linkAttribution] html += %Q[(function() {\n] html += %Q( var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n) if [:demographics] html += %Q( ga.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js';\n) else html += %Q( ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n) end html += %Q( var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n) html += %Q[})();\n</script>\n] html end |
#google_analytics_async ⇒ Object
16 17 18 19 20 |
# File 'lib/awestruct/extensions/google_analytics.rb', line 16 def google_analytics_async() # deprecated $LOG.warn "google_analytics_async is deprecated. Please use google_analytics or google_analytics_universal." if $LOG.warn? google_analytics() end |
#google_analytics_universal(options = {}) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/awestruct/extensions/google_analytics.rb', line 49 def google_analytics_universal(={}) = defaults() html = '' html += %Q(<script>\n) html += %Q( (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n ) html += %Q(\n) html += %Q(ga('create', '#{[:account]}', 'auto');\n) html += %Q(ga('send', 'pageview');\n) html += %Q(ga('set', 'anonymizeIp', true);\n) if [:anonymizeIp] html += %Q(ga('require', 'displayfeatures');\n) if [:demographics] html += %Q(ga('require', 'linkid', 'linkid.js');\n) if [:linkAttribution] html += %Q(setTimeout("ga('send', 'event', 'read', '#{[:bounceTime]} seconds')", #{[:bounceTime]}000);\n) if [:bounceTime] html += %Q(\n) html += %Q(</script>\n) html end |