#set_id_id = 1の場合、仕入先使用か使用しないかの設定
when 1
supplier_update
+ when 2
+ googleanalytics_update
else
#将来何か追加したい場合、ここで追加してください
render :action => "settings"
end
end
+ #GoogleAnalyticsを使用するかどうか設定
+ def googleanalytics_update
+ @system.attributes = params[:system]
+ if @system.googleanalytics_use_flag
+ @system.tracking_code = @system.tracking_code.gsub(/__UserAccount__/, @system.googleanalytics_account_num)
+ end
+ if @system.save
+ if @system.googleanalytics_use_flag
+ flash.now[:notice_google] = "GoogleAnalyticsを使用するように設定しました"
+ render :action => "settings"
+ else
+ flash.now[:notice_google] = "GoogleAnalyticsを使用しないように設定しました"
+ render :action => "settings"
+ end
+ else
+ flash.now[:error_google] = "設定に失敗しました"
+ render :action => "settings"
+ end
+ end
+
end
def validate_on_create
errors.add "","複数のデータは登録できません。" if System.count > 0
end
+
+ def validate
+ if self.googleanalytics_use_flag
+ if self.googleanalytics_account_num.size == 0 && self.tracking_code.size == 0
+ errors.add(:googleanalytics_account_num, "を入力してください。")
+ errors.add(:tracking_code, "を入力してください。")
+ elsif self.tracking_code.size == 0
+ errors.add(:tracking_code, "を入力してください。")
+ elsif self.googleanalytics_account_num.size == 0
+ errors.add(:googleanalytics_account_num, "を入力してください。")
+ end
+ end
+ if self.googleanalytics_account_num.size > 0
+ if self.googleanalytics_account_num =~ /[^A-Za-z0-9-]/
+ errors.add(:gooleanalytics_account_num, "を正しく入力してください")
+ end
+ end
+ end
+
+ validates_length_of :googleanalytics_account_num, :maximum=>20, :message=> 'は20文字以内で入力してください。'
+ validates_length_of :tracking_code, :maximum=>5000, :message=> 'は5000文字以内で入力してください。'
end
+<% content_for :head do %>
+<%= javascript_include_tag 'admin/googleanalytics' %>
+<% end %>
+
<%=h flash[:system_update] %>
<%=h flash[:error] %>
-<%= error_messages_for :system %>
+<%= error_messages_for :shops %>
<!--仕入先-->
<% form_for :system, :url =>{:action => "settings_update"} do |f|%>
+<div>
+<h3>仕入先</h3>
<table cellspacing="1" cellpadding="0" class="data" >
<tr>
<th>仕入先を使用しますか</th>
<td><%= f.radio_button :supplier_use_flag , false%>使用しない <%= f.radio_button :supplier_use_flag , true%>使用する</td>
</tr>
</table>
-<div class="btn_box">
- <%= hidden_field_tag "set_id","1"%>
+ <div class="btn_box">
+ <%= hidden_field_tag "set_id","1"%>
<%= submit_tag "この内容で登録する", :onclick => "return #{confirm_javascript_function("登録しても宜しいですか")}", :class=>"btn" %>
<%= image_tag("btn_side.gif", :width => "6", :height => "34", :class => "btn_side") %>
+ </div>
+</div>
+<% end %>
+<div class="clearfix" style="padding-bottom:10px;"></div>
+<% form_for :system, :url =>{:action => "settings_update"} do |f|%>
+<%=h flash[:notice_google] %>
+<%=h flash[:error_google] %>
+<%= error_messages_for :system %>
+<div>
+<h3>Google Analytics</h3>
+<table cellspacing="1" cellpadding="0" class="data" >
+ <tr>
+ <th>GoogleAnalyticsを使用しますか</th>
+ <td><%= f.radio_button :googleanalytics_use_flag , false%>使用しない <%= f.radio_button :googleanalytics_use_flag , true%>使用する</td>
+ </tr>
+ <tr>
+ <th>アカウント番号(UA-XXXXXX-X)</th>
+ <td><%= f.text_field :googleanalytics_account_num %>(20文字以内)</td>
+ </tr>
+ <tr>
+ <th>トラッキングコード</th>
+ <td>
+ <input type="button" value="同期" onclick="trackingCodeSynchronous(); return false;" class="btn_s" />
+ <input type="button" value="非同期" onclick="trackingCodeAsynchronous(); return false;" class="btn_s" />
+ <%= f.text_area :tracking_code, :cols => 70 %><br />
+ (5000文字以内)
+ <p class="req"><span class="pnt">※</span>登録すると、__UserAccount__にアカウント番号が入ります。</p>
+ </td>
+ </tr>
+</table>
+ <div class="btn_box">
+ <%= submit_tag "この内容で登録する", :onclick => "return #{confirm_javascript_function("登録しても宜しいですか")}", :class=>"btn" %>
+ <%= hidden_field_tag "set_id","2"%>
+ <img class="btn_side" width="6" height="34" src="/images/btn_side.gif" />
+ </div>
</div>
<% end %>
<h2>環境設定</h2>
<p class="req"><span class="pnt">※</span>は必須入力です</p>
-<h3>仕入先</h3>
+<!--仕入先-->
<%= render :partial => "settings_form" %>
</div><!-- /メイン -->
<a href="#header"><%= image_tag("common/pagetop_btn.gif", :width => "79", :height => "24", :alt => "page top") %></a>
</div>
</div><!-- /footer -->
+<!--GoogleAnalytics トラッキングコード-->
+<% if @system.googleanalytics_use_flag %>
+<%= @system.tracking_code %>
+<% end %>
+<!--トラッキングコード end-->
</body>
</html>
--- /dev/null
+class AddColumnGoogleAnalyticsToSystems < ActiveRecord::Migration
+ def self.up
+ add_column :systems, :googleanalytics_use_flag, :boolean,:default => false, :comment => "GoogleAnalytics利用可否"
+ add_column :systems, :googleanalytics_account_num, :string, :limit => 20, :comment =>"UA-XXXX-XXアカウント番号"
+ end
+
+ def self.down
+ remove_columns :systems, :googleanalytics_use_flag
+ remove_columns :systems, :googleanalytics_account_num
+ end
+end
--- /dev/null
+class AddColumnTrackingCodeToSystems < ActiveRecord::Migration
+ def self.up
+ add_column :systems, :tracking_code, :text, :comment =>"トラッキングコード"
+ end
+
+ def self.down
+ remove_columns :systems, :tracking_code
+ end
+end
--- /dev/null
+var synch = "<script type=\"text/javascript\">\n\
+var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\n\
+document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));\n\
+</script>\n\
+<script type=\"text/javascrip\">\n\
+try {\n\
+var pageTracker = _gat._getTracker(\"__UserAccount__\");\n\
+pageTracker._trackPageview();\n\
+} catch(err) {}</script>"
+
+var asynch = "<script type=\"text/javascript\">\n\
+\n\
+var _gaq = _gaq || [];\n\
+_gaq.push(['_setAccount', '__UserAccount__']);\n\
+_gaq.push(['_trackPageview']\n\
+\n\
+(function() {\n\
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n\
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n\
+(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);})();\n\
+\n\
+</script>"
+
+function trackingCodeSynchronous() {
+ var o = document.getElementById("system_tracking_code");
+ o.value = synch;
+}
+
+function trackingCodeAsynchronous() {
+ var p = document.getElementById("system_tracking_code");
+ p.value = asynch;
+}
\ No newline at end of file