find(:all)
g = Gruff::Bar.new(1000)
g.title = "Cost Per Sale Report"
g.legend_font_size = 16
g.y_axis_label = 'Cost (USD)'
advertisers.each do |a|
visitor_addresses = Hit.find(:all,
CHAPTER 10 n CALCULATING COSTS BY ANALYZING APACHE WEB LOGS 211
:group=>'remote_addr',
:conditions=>['http_referrer= ? ',
a.referrer_url]
).map { |h| h.remote_addr }
sale_count = Hit.count('remote_addr',
:conditions=>['remote_addr IN (?)
AND
path_info LIKE "/cart/checkout%"',
visitor_addresses])
total_cost = visitor_addresses.length*a.cost_per_click
cost_per_sale = total_cost / sale_count
g.data(a.company_name, [a.cost_per_click, cost_per_sale ] )
end
g.labels = {0 => 'Cost Per Click', 1 => 'Cost Per Sale' }
g.minimum_value = 0
g.write(graph_tempfile_name)
graph_tempfile_name
end
The graph options are slightly different from the get_visitor_graph_tempfile
function, but otherwise get_sale_graph_tempfile is similar to that function. The big difference
is that instead of simply displaying the total number of visitors, it displays the cost
per click and cost per sale.
Pages:
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305