move google analytics to partial

This commit is contained in:
xdite 2013-02-11 19:34:14 +08:00
parent 3047d8afa3
commit c95629a781
3 changed files with 22 additions and 16 deletions

View File

@ -0,0 +1,7 @@
module CommonHelper
def render_google_analytics_code
if Rails.env == "production" && SiteSetting.ga_tracking_code.present?
render :partial => "common/google_analytics"
end
end
end

View File

@ -0,0 +1,14 @@
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<%= SiteSetting.ga_tracking_code %>']);
_gaq.push(['_setCustomVar', 1, 'Anonymous', <%= !current_user %>, 2]);
_gaq.push(['_trackPageview']);
(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);
})();
</script>

View File

@ -124,22 +124,7 @@
Discourse.initialize()
</script>
<%- if Rails.env == "production" and SiteSetting.ga_tracking_code.present? %>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<%= SiteSetting.ga_tracking_code %>']);
_gaq.push(['_setCustomVar', 1, 'Anonymous', <%= !current_user %>, 2]);
_gaq.push(['_trackPageview']);
(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);
})();
</script>
<%-end%>
<%= render_google_analytics_code %>
</body>
</html>