Move piwik code to a static JS asset

This commit is contained in:
Tom Hughes 2012-09-05 23:05:07 +01:00
parent 24453e7230
commit 7c0055b5d7
6 changed files with 30 additions and 15 deletions

View file

@ -6,6 +6,7 @@
//= require openlayers
//= require i18n/translations
//= require globals
//= require piwik
//= require browse
//= require export
//= require map

View file

@ -1,4 +1,8 @@
OSM = {
<% if defined?(PIWIK_LOCATION) and defined?(PIWIK_SITE) %>
PIWIK_LOCATION: <%= PIWIK_LOCATION.to_json %>,
PIWIK_SITE: <%= PIWIK_SITE.to_json %>,
<% end %>
MAX_REQUEST_AREA: <%= MAX_REQUEST_AREA.to_json %>,
SERVER_URL: <%= SERVER_URL.to_json %>,
API_VERSION: <%= API_VERSION.to_json %>

View file

@ -0,0 +1,21 @@
if (OSM.PIWIK_LOCATION && OSM.PIWIK_SITE) {
$(document).ready(function () {
var base = document.location.protocol + "//" + OSM.PIWIK_LOCATION + "/";
$.ajax({
url: base + "piwik.js",
dataType: "script",
cache: true,
success: function () {
var piwikTracker = Piwik.getTracker(base + "piwik.php", OSM.PIWIK_SITE);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
$("meta[name=piwik-goal]").each(function () {
piwikTracker.trackGoal($(this).attr("content"));
});
}
});
});
}

View file

@ -11,6 +11,9 @@
<%= tag("link", { :rel => "publisher", :href => "https://plus.google.com/111953119785824514010" }) %>
<%= tag("link", { :rel => "search", :type => "application/opensearchdescription+xml", :title => "OpenStreetMap Search", :href => asset_path("osm.xml") }) %>
<%= tag("meta", { :name => "description", :content => "OpenStreetMap is the free wiki world map." }) %>
<% if flash[:piwik_goal] -%>
<%= tag("meta", :name => "piwik-goal", :content => flash[:piwik_goal]) %>
<% end -%>
<%= style_rules %>
<%= yield :head %>
<%= csrf_meta_tag %>

View file

@ -1,14 +0,0 @@
<script type="text/javascript">
var _paq = _paq || [];
(function(){ var u="<%= request.protocol %><%= PIWIK_LOCATION %>/";
_paq.push(['setSiteId', <%= PIWIK_SITE %>]);
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
<% if flash[:piwik_goal] -%>
_paq.push(['trackGoal', <%= flash[:piwik_goal] %>);
<% end -%>
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript'; g.defer=true; g.async=true; g.src=u+'piwik.js';
s.parentNode.insertBefore(g,s); })();
</script>
<noscript><p><img src="<%= request.protocol %><%= PIWIK_LOCATION %>/piwik.php?idsite=<%= PIWIK_SITE %>" style="border:0" alt="" /></p></noscript>

View file

@ -144,7 +144,7 @@
</div>
<% if defined?(PIWIK_LOCATION) and defined?(PIWIK_SITE) -%>
<%= render :partial => "layouts/piwik" %>
<noscript><p><img src="<%= request.protocol %><%= PIWIK_LOCATION %>/piwik.php?idsite=<%= PIWIK_SITE %>" style="border:0" alt="" /></p></noscript>
<% end -%>
</body>
</html>