Skip to content

Instantly share code, notes, and snippets.

@julesce
Created January 14, 2014 09:01
Show Gist options
  • Select an option

  • Save julesce/8415308 to your computer and use it in GitHub Desktop.

Select an option

Save julesce/8415308 to your computer and use it in GitHub Desktop.
def self.new_count(mailing, stat_type)
case stat_type
when :total
Total.new(mailing, stat_type).count
when :ga
GoogleAnalyticsMailingStat.total_value(mailing)
when :total_viewed
PromotionAttemptEvent.count_by_state(mailing.id, stat_type) + archive_count(mailing, :viewed)
when :tweeted, :facebooked, :plusoned, :pinned, :forwarded, :shared,
:forward_total_viewed, :subscribed
PromotionAttemptEvent.count_by_state(mailing.id, stat_type)
when :engaged
PromotionAttemptEvent.count_by_state(mailing.id, stat_type, :unique => true)
when :clicked, :total_clicked, :forward_total_clicked
Clicks.new(mailing, stat_type).count
else
# Stats based on (R)PromotionAttempt models: viewed sent accepted
# opt_out spam bounced hard_bounced soft_bounced other_bounced
State.new(mailing, stat_type).count
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment