Add click tracking for banner links
This commit is contained in:
parent
6bfcc946a4
commit
06c6a100ce
|
|
@ -1,4 +1,5 @@
|
||||||
class AdBannersController < ApplicationController
|
class AdBannersController < ApplicationController
|
||||||
|
skip_before_action :verify_authenticity_token, only: [:track_click]
|
||||||
def self.custom_widget_data
|
def self.custom_widget_data
|
||||||
ac = ActionController::Base.new
|
ac = ActionController::Base.new
|
||||||
ac.instance_variable_set(:@custom_data_field, @custom_data_field)
|
ac.instance_variable_set(:@custom_data_field, @custom_data_field)
|
||||||
|
|
@ -15,6 +16,14 @@ class AdBannersController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def track_click
|
||||||
|
ad_image = AdImage.find(params[:id])
|
||||||
|
ad_image.inc(click_count: 1)
|
||||||
|
head :ok
|
||||||
|
rescue Mongoid::Errors::DocumentNotFound
|
||||||
|
head :not_found
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def image_widget(adbanner)
|
def image_widget(adbanner)
|
||||||
|
|
@ -34,7 +43,7 @@ class AdBannersController < ApplicationController
|
||||||
target = ""
|
target = ""
|
||||||
end
|
end
|
||||||
if !b.out_link.blank?
|
if !b.out_link.blank?
|
||||||
image_link += "\" style=\"cursor:pointer;\" onload=\"var el=this;(function(){if((el.parentElement==undefined||el.parentElement.tagName!='A')&&$('<p>'+$(el).parents('.w-ba-banner__slide').eq(0).attr('data-overlay-template')+'</p>').find('a').length==0){el.outerHTML=('<a href=#{b.out_link} target=#{target}>'+el.outerHTML+'</a>');}})()\""
|
image_link += "\" style=\"cursor:pointer;\" onclick=\"if(navigator.sendBeacon){navigator.sendBeacon('/ad_banners/track_click/#{b.id}');}\" onload=\"var el=this;(function(){if((el.parentElement==undefined||el.parentElement.tagName!='A')&&$('<p>'+$(el).parents('.w-ba-banner__slide').eq(0).attr('data-overlay-template')+'</p>').find('a').length==0){el.outerHTML=('<a href=#{b.out_link} target=#{target}>'+el.outerHTML+'</a>');}})()\""
|
||||||
end
|
end
|
||||||
context = (b.context.tr('"',"'") rescue "")
|
context = (b.context.tr('"',"'") rescue "")
|
||||||
images << {
|
images << {
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class Admin::AdBannersController < OrbitAdminController
|
||||||
else
|
else
|
||||||
@images = @banner.ad_images.not_expired.order_by(is_top: -1, sort_number: 1).page(params[:page]).per(10)
|
@images = @banner.ad_images.not_expired.order_by(is_top: -1, sort_number: 1).page(params[:page]).per(10)
|
||||||
end
|
end
|
||||||
@table_fields = [:banner, :title, "ad_banner.duration", :link]
|
@table_fields = [:banner, :title, "ad_banner.duration", :link, "click_count"]
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
|
|
||||||
|
|
@ -60,4 +60,4 @@ class Admin::AdImagesController < Admin::AdBannersController
|
||||||
def setup_vars
|
def setup_vars
|
||||||
@module_app = ModuleApp.where(:key => "ad_banner").first
|
@module_app = ModuleApp.where(:key => "ad_banner").first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ class AdImage
|
||||||
field :is_top, :type => Boolean, :default => false
|
field :is_top, :type => Boolean, :default => false
|
||||||
field :language_enabled, :type => Array, :default => ["en","zh_tw"]
|
field :language_enabled, :type => Array, :default => ["en","zh_tw"]
|
||||||
field :exchange_item, :default => "1"
|
field :exchange_item, :default => "1"
|
||||||
|
field :click_count, type: Integer, default: 0
|
||||||
LINK_OPEN_TYPES = ["local", "new_window"]
|
LINK_OPEN_TYPES = ["local", "new_window"]
|
||||||
|
|
||||||
belongs_to :banner
|
belongs_to :banner
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,8 @@
|
||||||
<% if image.out_link != "" %>
|
<% if image.out_link != "" %>
|
||||||
<a href="<%= image.out_link rescue "#" %>" target="_blank">Link</a>
|
<a href="<%= image.out_link rescue "#" %>" target="_blank">Link</a>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
|
<td><%= image.click_count %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
||||||
|
|
@ -46,4 +46,5 @@ zh_tw:
|
||||||
type: 圖片 或 影片
|
type: 圖片 或 影片
|
||||||
choose_type: 請先選擇類型
|
choose_type: 請先選擇類型
|
||||||
select: 請選擇
|
select: 請選擇
|
||||||
video: 影片
|
click_count: "點擊次數"
|
||||||
|
video: 影片
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
require 'fileutils'
|
require 'fileutils'
|
||||||
get 'ad_banners/widget'
|
get 'ad_banners/widget'
|
||||||
|
post 'ad_banners/track_click/:id', to: 'ad_banners#track_click', as: 'ad_banner_track_click'
|
||||||
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
|
if ENV['worker_num']=='0' && File.basename($0) != 'rake' && !Rails.const_defined?('Console')
|
||||||
Thread.new do
|
Thread.new do
|
||||||
s = Site.first
|
s = Site.first
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue