Prev | Current Page 381 | Next

David Berube

"Practical Reporting with Ruby and Rails"

to_f
results_raw=AdResult.find(:all,
:select=>'headline,
AVG(cost) as cost,
AVG(clicks) as clicks',
:group=>'headline')
results_raw.sort! { |x,y| ((x.cost/x.clicks) <=> (y.cost/y.clicks)) }
CHAPTER 13 n TRACKING YOUR ADS WITH GOOGLE ADWORDS 278
The first method, index, just displays a form allowing the user to select a goal with a
number of clicks. The second method, report, actually creates the report. You first grab
the parameters passed to the action, and then grab the average cost and number of clicks
for each distinct headline. This means that for each time period in the report, the cost
and number of clicks will be averaged and returned for that headline.
nNote This code analyzes ads by headline, so multiple ads with the same headline and different body copy
will be grouped together. In most cases, an ad with an identical headline and different body copy is simply
going to be a variation on a theme, such as an attempt to see which ad has a higher click-through rate, not
an ad with a completely different subject matter.


Pages:
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393