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
|
@tags = @module_app.tags
|
||||||
@categories = @module_app.categories.enabled
|
@categories = @module_app.categories.enabled
|
||||||
@filter_fields = filter_fields(@categories, @tags)
|
@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?
|
if params[:sort].blank?
|
||||||
s = {:order_position => "asc"}
|
s = {:order_position => "asc"}
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
class WebResourcesController < ApplicationController
|
class WebResourcesController < ApplicationController
|
||||||
require 'nokogiri'
|
require 'nokogiri'
|
||||||
|
skip_before_action :verify_authenticity_token, only: [:track_click]
|
||||||
def index
|
def index
|
||||||
OrbitHelper.render_css_in_head(["web_resources_front"])
|
OrbitHelper.render_css_in_head(["web_resources_front"])
|
||||||
links = WebLink.where(:title.ne => "").can_display.filter_by_categories.filter_by_tags
|
links = WebLink.where(:title.ne => "").can_display.filter_by_categories.filter_by_tags
|
||||||
|
|
@ -33,7 +34,8 @@ class WebResourcesController < ApplicationController
|
||||||
"statuses" => statuses,
|
"statuses" => statuses,
|
||||||
"category" => link.category.title,
|
"category" => link.category.title,
|
||||||
"link_to_show" => link.url,
|
"link_to_show" => link.url,
|
||||||
"target" => target
|
"target" => target,
|
||||||
|
"onclick" => "if(navigator.sendBeacon){navigator.sendBeacon('/web_resources/track_click/#{link.id}');}"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
{
|
{
|
||||||
|
|
@ -79,7 +81,8 @@ class WebResourcesController < ApplicationController
|
||||||
"context" => nl2br(link.context.to_s),
|
"context" => nl2br(link.context.to_s),
|
||||||
"statuses" => statuses,
|
"statuses" => statuses,
|
||||||
"link_to_show" => link.url,
|
"link_to_show" => link.url,
|
||||||
"target" => target
|
"target" => target,
|
||||||
|
"onclick" => "if(navigator.sendBeacon){navigator.sendBeacon('/web_resources/track_click/#{link.id}');}"
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
{
|
{
|
||||||
|
|
@ -87,4 +90,12 @@ class WebResourcesController < ApplicationController
|
||||||
"extras" => {"widget-title"=>t(:web_resource),"more_url" => OrbitHelper.widget_more_url}
|
"extras" => {"widget-title"=>t(:web_resource),"more_url" => OrbitHelper.widget_more_url}
|
||||||
}
|
}
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,14 @@ class WebLink
|
||||||
field :create_user_id
|
field :create_user_id
|
||||||
field :update_user_id
|
field :update_user_id
|
||||||
field :rss2_id, type: String
|
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
|
field :link_open, type: String
|
||||||
LINK_OPEN_TYPES = ["local", "new_window"]
|
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
|
before_save :add_http
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,22 @@
|
||||||
</div>
|
</div>
|
||||||
</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>
|
</div>
|
||||||
|
|
||||||
<!-- Status Module -->
|
<!-- Status Module -->
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
|
<td><%= format_value link.postdate %> ~ <%= format_value link.deadline %></td>
|
||||||
|
<td><%= link.click_count %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
Rails.application.routes.draw do
|
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
|
locales = Site.find_by(site_active: true).in_use_locales rescue I18n.available_locales
|
||||||
|
|
||||||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue