diff --git a/misc/plugin/amp.rb b/misc/plugin/amp.rb
index 7cfa0058a..e40195c7c 100644
--- a/misc/plugin/amp.rb
+++ b/misc/plugin/amp.rb
@@ -19,12 +19,47 @@
ERB.new(template).result(binding)
end
+add_conf_proc('amp', 'AMP') do
+ if @mode == 'saveconf'
+ @conf['amp.analytics.trackingid'] = @cgi.params['amp.analytics.trackingid'][0]
+ end
+ <<-HTML
+
Google Analytics
+ your tracking ID (NNNNN-N)
+
+ HTML
+end
+
def amp_body(diary)
apply_plugin(diary.to_html)
.gsub(/]+)>/, '')
.gsub(/
+
+ HTML
+ end
+ body_scripts
+end
+
def amp_canonical_url(diary)
URI.join(@conf.base_url, anchor(diary.date.strftime('%Y%m%d')))
end
@@ -33,6 +68,16 @@ def amp_day_title(diary)
title_proc(Time::at(@date.to_i), diary.title)
end
+def amp_header_scripts
+ scripts = {}
+ if @conf['amp.analytics.trackingid'] && ! @conf['amp.analytics.trackingid'].empty?
+ scripts['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js'
+ end
+ scripts.map {|element, src|
+ %Q||
+ }.join("\n")
+end
+
def amp_html_url(diary)
URI.join(amp_canonical_url(diary), '?plugin=amp')
end
diff --git a/views/amp.rhtml b/views/amp.rhtml
index 452a64964..f2eb8e304 100644
--- a/views/amp.rhtml
+++ b/views/amp.rhtml
@@ -2,6 +2,7 @@
+ <%= amp_header_scripts %>
<%= amp_title %>
@@ -12,6 +13,7 @@
+ <%= amp_body_scripts %>