0

我正在使用没有 Rails 的 Ruby 1.9.3 和 Gibbon gem 的 1.0.4 版本。

我的列表中填充了推荐,并且可以使用 Gibbon 将以下内容发送到 MailChimp。但是,MailChimp 的列表中只填充了电子邮件地址和电子邮件类型字段。我做错了什么禁止通过 API 导入所有合并字段?

这是列表的批次和地图。

referrals.each_slice(3) do |batch|
  begin
    prepared_batch = batch.map do |referral|
      { 
        :EMAIL => {:email => referral['client_email']}, 
        :EMAIL_TYPE => 'html', 
        :MMERGE6 => referral['field_1'],
        :MMERGE7 => referral['field_2'],
        :MMERGE8 => referral['field_3'],
        :MMERGE9 => referral['field_4'],
        :MMERGE11 => referral['field_5'],
        :MMERGE12 => referral['field_6'],
        :MMERGE13 => referral['field_7'],
        :MMERGE14 => referral['field_8'],
        :MMERGE15 => referral['field_9'],
        :FNAME => referral['client_first_name']
      }
    end
    @log.info("prepared_batch : #{prepared_batch}")

result = @gibbon.lists.batch_subscribe(
  :id => @mc_list_id, 
  :batch => prepared_batch,
  :double_optin => false,
  :update_existing => true
)
@log.info("#{result}")

  rescue Exception => e
    @log.warn("Unable to load batch into mailchimp because #{e.message}")
  end
end

以上执行成功。但是,仅填充了电子邮件地址和电子邮件类型,但应填充大部分字段。

这是我对prepared_batches 之一的日志输出。我用价值替换了实际价值。我使用自己的电子邮件进行测试。

I, [2013-11-11T09:01:14.778907 #70827]  INFO -- : prepared_batch : [{:EMAIL=>
{:email=>"jason+6@marketingscience.co"}, :EMAIL_TYPE=>"html", :MMERGE6=>"Value",
 :MMERGE7=>"Value", :MMERGE8=>nil, :MMERGE9=>nil, :MMERGE11=>"8/6/13 0:00",
 :MMERGE12=>"Value", :MMERGE13=>nil, :MMERGE14=>"10/18/13 19:09", :MMERGE15=>"Value",
 :FNAME=>"Value"}, {:EMAIL=>{:email=>"jason+7@marketingscience.co"}, :EMAIL_TYPE=>"html",
 :MMERGE6=>"Value", :MMERGE7=>"Value", :MMERGE8=>nil, :MMERGE9=>nil, :MMERGE11=>"8/6/13
 0:00", :MMERGE12=>"Value", :MMERGE13=>nil, :MMERGE14=>nil, :MMERGE15=>"Value",
 :FNAME=>"Value"}, {:EMAIL=>{:email=>"jason+8@marketingscience.co"}, :EMAIL_TYPE=>"html",
 :MMERGE6=>"Value", :MMERGE7=>"Value", :MMERGE8=>nil, :MMERGE9=>nil, :MMERGE11=>"8/7/13
 0:00", :MMERGE12=>"Value", :MMERGE13=>nil, :MMERGE14=>nil, :MMERGE15=>"Value",
 :FNAME=>"Value"}]

这是 MailChimp 调用结果的日志输出。

I, [2013-11-11T09:01:14.778691 #70827]  INFO -- : {"add_count"=>3, "adds"=>
[{"email"=>"jason+3@marketingscience.co", "euid"=>"ab512177b4", "leid"=>"54637465"},
 {"email"=>"jason+4@marketingscience.co", "euid"=>"eeb8388524", "leid"=>"54637469"},
 {"email"=>"jason+5@marketingscience.co", "euid"=>"7dbc84cb75", "leid"=>"54637473"}],
 "update_count"=>0, "updates"=>[], "error_count"=>0, "errors"=>[]} 

任何有关如何在 MailChimp 中更新所有字段的建议都值得赞赏。谢谢。

4

1 回答 1

1

原来使用 Gibbon gem 批量订阅的文档不正确。您需要添加 :merge_vars 结构以包含电子邮件和电子邮件类型以外的字段。我的最终代码如下所示。我还将在以下位置完整更新此代码:https ://gist.github.com/analyticsPierce/7434085 。

referrals.each_slice(3) do |batch|
  begin
    prepared_batch = batch.map do |referral|
      { 
        :EMAIL => {:email => referral['email']}, 
        :EMAIL_TYPE => 'html', 
        :merge_vars => {
        :MMERGE6 => referral['field_1'],
        :MMERGE7 => referral['field_2'],
        :MMERGE8 => referral['field_3'],
        :MMERGE9 => referral['field_4'],
        :MMERGE11 => referral['field_5'],
        :MMERGE12 => referral['field_6'],
        :MMERGE13 => referral['field_7'],
        :MMERGE14 => referral['field_8'],
        :MMERGE15 => referral['field_9'],
        :FNAME => referral['first_name']
        } 
      }
    end
    @log.info("prepared_batch : #{prepared_batch}")
    result = @gibbon.lists.batch_subscribe(
      :id => @mc_list_id, 
      :batch => prepared_batch,
      :double_optin => false,
      :update_existing => true
    )
    @log.info("#{result}")
  rescue Exception => e
    @log.warn("Unable to load batch into mailchimp because #{e.message}")
  end
end
于 2013-11-12T16:36:38.710 回答