Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add ability to set google analytics options for individual email type…

…s in a mailer.
  • Loading branch information...
commit 86f30aab16ededac2a9d8e264590d9a4b9d04efd 1 parent c3c7f99
@peregrinator peregrinator authored
Showing with 22 additions and 0 deletions.
  1. +22 −0 lib/sendgrid.rb
View
22 lib/sendgrid.rb
@@ -13,6 +13,14 @@ module SendGrid
:bypass_list_management
]
+ VALID_GANALYTICS_OPTIONS = [
+ :utm_source,
+ :utm_medium,
+ :utm_campaign,
+ :utm_term,
+ :utm_content
+ ]
+
def self.included(base)
base.class_eval do
class << self
@@ -130,6 +138,13 @@ def sendgrid_footer_text(texts)
def sendgrid_spamcheck_maxscore(score)
@spamcheck_score = score
end
+
+ # Call within mailer method to set custom google analytics options
+ # http://sendgrid.com/documentation/appsGoogleAnalytics
+ def sengrid_ganalytics_options(options)
+ @ganalytics_options = []
+ options.each { |option| @ganalytics_options << option if VALID_GANALYTICS_OPTIONS.include?(option) }
+ end
# Sets the custom X-SMTPAPI header after creating the email but before delivery
def create!(method_name, *parameters)
@@ -231,6 +246,13 @@ def filters_hash_from_options(enabled_opts, disabled_opts)
if self.class.default_spamcheck_score || @spamcheck_score
filters[:spamcheck]['settings']['maxscore'] = @spamcheck_score || self.class.default_spamcheck_score
end
+
+ when :ganalytics
+ if @ganalytics_options
+ @ganalytics_options.each do |key, value|
+ filters[:ganalytics]['settings'][key.to_s] = value
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.