使用MailChimp API V3.0创建包含动态细分的广告系列

问题描述 投票:4回答:2

使用MailChimp API V3.0创建活动。

我想创建一个发送给具有特定兴趣的用户的广告系列。看起来这在文档中是可行的,但我已经尝试了我能想到的每一种排列。只要我省略了segment_ops成员,我就可以创建广告系列。有没有人有PHP代码的例子呢?

由于您在通过API设置用户兴趣时未包含兴趣类别,因此似乎奇怪地处理了兴趣。我不确定这会如何影响广告系列的制作。

php mailchimp segment mailchimp-api-v3.0
2个回答
15
投票

我已经得到了这个工作,虽然你无法从当前的文档中获得它,这些文档没有列出'兴趣'condition_type或者可能的'op'值。

兴趣必须按兴趣类别分组(在UI的某些部分称为“组”)。

以下是recipients数组的segment_opts成员的JSON:

 "segment_opts": {
        "match": "any",
        "conditions": [{
            "condition_type": "Interests",
            "field": "interests-31f7aec0ec",
            "op": "interestcontains",
            "value": ["a9014571b8", "5e824ac953"]
        }]
 }

这是带有注释的PHP数组版本。 'match'成员引用'条件'数组中的规则。该段可以匹配任何,所有或任何条件。此示例只有一个条件,但其他条件可以作为“条件”数组中的附加数组添加:

$segment_opts = array(
'match' => 'any', // or 'all' or 'none'
'conditions' => array (
    array(
        'condition_type' => 'Interests', // note capital I
        'field' => 'interests-31f7aec0ec', // ID of interest category
                                           // This ID is tricky: it is 
                                           // the string "interests-" + 
                                           // the ID of interest category
                                           // that you get from MailChimp 
                                           // API (31f7aec0ec)
        'op' => 'interestcontains', // or interestcontainsall, interestcontainsnone
        'value' => array (
            'a9014571b8',  // ID of interest in that category
            '5e824ac953' // ID of another interest in that category
        )
    )

  )
);

0
投票

您也可以发送到已保存的细分。问题在于,segment_id必须是int。我在db中将此值保存为varchar,除非转换为int,否则它将无法工作。

(我使用的是\ DrewM \ MailChimp \ MailChimp;)

$segment_id =  (int) $methodThatGetsMySegmentID;

$campaign = $MailChimp->post("campaigns", [
    'type' => 'regular',
    'recipients' => array(
        'list_id' => 'abc123yourListID',
        'segment_opts' => array(
            'saved_segment_id' => $segment_id,
        ),
    ),
    'settings' => array(
        'subject_line' => 'A New Article was Posted',
        'from_name' => 'From Name',
        'reply_to' => '[email protected]',
        'title' => 'New Article Notification'
    )
]);
© www.soinside.com 2019 - 2024. All rights reserved.