Add click tracking and display period to web resource links
This commit is contained in:
parent
76d317d9bb
commit
e6e280c73b
|
|
@ -6,7 +6,7 @@ class Admin::WebResourcesController < OrbitAdminController
|
|||
@tags = @module_app.tags
|
||||
@categories = @module_app.categories.enabled
|
||||
@filter_fields = filter_fields(@categories, @tags)
|
||||
@table_fields = [:status, :category, :title]
|
||||
@table_fields = [:status, :category, :title, "ad_banner.duration", "click_count"]
|
||||
if params[:sort].blank?
|
||||
s = {:order_position => "asc"}
|
||||
else
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
class WebResourcesController < ApplicationController
|
||||
require 'nokogiri'
|
||||
skip_before_action :verify_authenticity_token, only: [:track_click]
|
||||
def index
|
||||
OrbitHelper.render_css_in_head(["web_resources_front"])
|
||||
links = WebLink.where(:title.ne => "").can_display.filter_by_categories.filter_by_tags
|
||||
|
|
@ -33,7 +34,8 @@ class WebResourcesController < ApplicationController
|
|||
"statuses" => statuses,
|
||||
"category" => link.category.title,
|
||||
"link_to_show" => link.url,
|
||||
"target" => target
|
||||
"target" => target,
|
||||
"onclick" => "if(navigator.sendBeacon){navigator.sendBeacon('/web_resources/track_click/#{link.id}');}"
|
||||
}
|
||||
end
|
||||
{
|
||||
|
|
@ -79,7 +81,8 @@ class WebResourcesController < ApplicationController
|
|||
"context" => nl2br(link.context.to_s),
|
||||
"statuses" => statuses,
|
||||
"link_to_show" => link.url,
|
||||
"target" => target
|
||||
"target" => target,
|
||||
"onclick" => "if(navigator.sendBeacon){navigator.sendBeacon('/web_resources/track_click/#{link.id}');}"
|
||||
}
|
||||
end
|
||||
{
|
||||
|
|
@ -87,4 +90,12 @@ class WebResourcesController < ApplicationController
|
|||
"extras" => {"widget-title"=>t(:web_resource),"more_url" => OrbitHelper.widget_more_url}
|
||||
}
|
||||
end
|
||||
|
||||
def track_click
|
||||
link = WebLink.find(params[:id])
|
||||
link.inc(click_count: 1)
|
||||
head :ok
|
||||
rescue Mongoid::Errors::DocumentNotFound
|
||||
head :not_found
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -18,12 +18,15 @@ class WebLink
|
|||
field :create_user_id
|
||||
field :update_user_id
|
||||
field :rss2_id, type: String
|
||||
field :click_count, type: Integer, default: 0
|
||||
field :postdate, type: DateTime, default: Time.now
|
||||
field :deadline, type: DateTime
|
||||
|
||||
field :link_open, type: String
|
||||
LINK_OPEN_TYPES = ["local", "new_window"]
|
||||
|
||||
scope :can_display, ->{where(is_hidden: false).order_by([:is_top,:desc],[:order_position,:asc])}
|
||||
|
||||
scope :can_display, ->{where(is_hidden: false).and(WebLink.unscoped.or({:postdate.lte=>Time.now},{:postdate=>nil}).selector,WebLink.unscoped.or({:deadline.gte=>Time.now},{:deadline=>nil}).selector).order_by([:is_top,:desc],[:order_position,:asc])}
|
||||
|
||||
before_save :add_http
|
||||
|
||||
protected
|
||||
|
|
@ -41,4 +44,4 @@ class WebLink
|
|||
self.url_translations = temp_url
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -33,6 +33,22 @@
|
|||
<%= select_category(f, @module_app) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Date Time Picker -->
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t(:start_date) %></label>
|
||||
<div class="controls">
|
||||
<%= f.datetime_picker :postdate, :no_label => true, :new_record => @link.new_record? %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Date Time Picker -->
|
||||
<div class="control-group">
|
||||
<label class="control-label muted"><%= t(:end_date) %></label>
|
||||
<div class="controls">
|
||||
<%= f.datetime_picker :deadline, :no_label => true, :new_record => @link.new_record? %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
|
@ -254,4 +270,4 @@
|
|||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
<td><%= format_value link.postdate %> ~ <%= format_value link.deadline %></td>
|
||||
<td><%= link.click_count %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
@ -31,4 +33,4 @@
|
|||
content_tag(:div, paginate(@links), class: "pagination pagination-centered") +
|
||||
content_tag(:div, link_to(t(:new_),new_admin_web_resource_path, :class=>"btn btn-primary"), class: "pull-right")
|
||||
end
|
||||
%>
|
||||
%>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
Rails.application.routes.draw do
|
||||
|
||||
post 'web_resources/track_click/:id', to: 'web_resources#track_click', as: 'web_resource_track_click'
|
||||
|
||||
locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_locales
|
||||
|
||||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||
|
|
|
|||
Loading…
Reference in New Issue