Class: MailSpy::TrackingController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- MailSpy::TrackingController
- Defined in:
- app/controllers/mail_spy/tracking_controller.rb
Instance Method Summary collapse
Instance Method Details
#action ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/mail_spy/tracking_controller.rb', line 48 def action email_id = params[:eid] action_type = params[:action_type] count = params[:count] || 1 details = params[:details] || {} head :unprocessable_entity and return if email_id.blank? || action_type.blank? head :unprocessable_entity and return if details.present? && !details.kind_of?(Hash) MailSpy.track_action(email_id, action_type, details, count) head 200 end |
#bug ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/mail_spy/tracking_controller.rb', line 35 def bug email_id = params[:eid] head :unprocessable_entity and return if email_id.blank? #Mark the email as opened email = MailSpy::Email.find(email_id) email.actions.create!( :action_type => MailSpy::Action::ACTION_TYPE_OPEN ) head 200 end |
#link ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/mail_spy/tracking_controller.rb', line 4 def link email_id = params[:eid] head :unprocessable_entity and return if email_id.blank? email = MailSpy::Email.find(email_id) email.actions.create!( :action_type => MailSpy::Action::ACTION_TYPE_CLICK, :details => { :url => params[:url], :link_number => params[:n] } ) # Add in the GA tokens if present ga_hash = {} ga_hash[:utm_source] = email.utm_source if email.utm_source.present? ga_hash[:utm_medium] = email.utm_medium if email.utm_medium.present? ga_hash[:utm_campaign] = email.utm_campaign if email.utm_campaign.present? ga_hash[:utm_term] = email.utm_term if email.utm_term.present? ga_hash[:utm_content] = email.utm_content if email.utm_content.present? #TODO this is not fool proof, it breaks on bad urls (like missing http://) #TODO this also breaks when a param is already present it isn;t smart uri = URI.parse(params[:url]) uri.query = [uri.query, ga_hash.to_param].compact.join('&') redirect_to uri.to_s end |