docbrown/app/services/notifications/welcome_notification/send.rb
Vaidehi Joshi 35b516a60d
Add metrics around welcome notifications + their click events (#9239)
* Log to DataDog when a welcome notification is created

* Fix typo in Metrics::RecordDailyUsageWorker

* Add Metrics::RecordDailyNotificationsWorker to log notification counts to DataDog

* Add specs around DataDog logging for welcome notifications + click events

* Call Metrics::RecordDailyNotificationsWorker from within log_daily_usage_measurables task

* Use user_id instead of user, move notification title into tags
2020-07-10 12:30:45 +02:00

49 lines
1.2 KiB
Ruby

# Creates and sends a specific welcome notification.
module Notifications
module WelcomeNotification
class Send
def initialize(receiver_id, welcome_broadcast)
@receiver_id = receiver_id
@welcome_broadcast = welcome_broadcast
end
delegate :user_data, to: Notifications
def self.call(*args)
new(*args).call
end
def call
mascot_account = User.mascot_account
json_data = {
user: user_data(mascot_account),
broadcast: {
title: welcome_broadcast.title,
processed_html: welcome_broadcast.processed_html,
type_of: welcome_broadcast.type_of
}
}
Notification.create!(
user_id: receiver_id,
notifiable_id: welcome_broadcast.id,
notifiable_type: "Broadcast",
action: welcome_broadcast.type_of,
json_data: json_data,
)
log_to_datadog
end
private
attr_reader :receiver_id, :welcome_broadcast
def log_to_datadog
DatadogStatsClient.increment(
"notifications.welcome",
tags: ["user_id:#{receiver_id}", "title:#{welcome_broadcast.title}"],
)
end
end
end
end