mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 01:16:38 -06:00
move google analytics to partial
This commit is contained in:
parent
3047d8afa3
commit
c95629a781
7
app/helpers/common_helper.rb
Normal file
7
app/helpers/common_helper.rb
Normal 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
|
14
app/views/common/_google_analytics.html.erb
Normal file
14
app/views/common/_google_analytics.html.erb
Normal 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>
|
@ -124,22 +124,7 @@
|
|||||||
Discourse.initialize()
|
Discourse.initialize()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<%- if Rails.env == "production" and SiteSetting.ga_tracking_code.present? %>
|
<%= render_google_analytics_code %>
|
||||||
<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%>
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user