Created
February 14, 2013 23:09
-
-
Save natarius/4957245 to your computer and use it in GitHub Desktop.
Automatically add the users that sign up to your rails app to a mailchimp list. I usually do this async via Resque and not exactly like in this snippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Gibbon.api_key = ENV["MAILCHIMP_API_KEY"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'gibbon' | |
after_create :sync_with_mailchimp | |
def sync_with_mailchimp | |
begin | |
list_name = "signed up users" | |
cm_user_list = Gibbon.lists({:filters => {:list_name => list_name}}) | |
cm_user_list_id = cm_user_list["data"].first["id"] | |
Gibbon.list_subscribe( | |
{ | |
:id => cm_user_list_id, | |
:email_address => self.email, | |
:double_optin => false, | |
:update_existing => true, | |
:merge_vars => {:FNAME => self.get_first_name, :LNAME => self.get_last_name} | |
} | |
) | |
rescue => e | |
Rails.logger.error "Error adding new user to mailchimp. Msg: #{e}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment