Created
September 10, 2011 02:42
-
-
Save stim371/1207859 to your computer and use it in GitHub Desktop.
app helper to place google analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def google_analytics_js | |
content_tag(:script, :type => 'text/javascript') do | |
"var _gaq || []; | |
_gaq.push(['_setAccount', 'XX-XXXXXXXX-X']); | |
_gaq.push(['_trackPageview']); | |
(function() { | |
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | |
ga.src = document.getElementByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
})();" | |
end if Rails.env.production? | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#this function allows you to input your account id when you call the function | |
module ApplicationHelper | |
def google_analytics_js(id = nil) | |
content_tag(:script, :type => 'text/javascript') do | |
"var _gaq || []; | |
_gaq.push(['_setAccount', '#{id}']); | |
_gaq.push(['_trackPageview']); | |
(function() { | |
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | |
ga.src = document.getElementByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
})();" | |
end if !id.blank? && Rails.env.production? | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= google_analytics_js 'XX-XXXXXXXX-X' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= google_analytics_js %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace the XX-XXXXXXXX-X with your specific google analytics account number.