lukeyouell/craft-mailchimplists

此包已被弃用,不再维护。未建议替代包。

在Craft中创建、管理和监控您的MailChimp列表。

安装数: 14,992

依赖: 1

建议者: 0

安全: 0

星级: 27

关注者: 0

分支: 5

开放问题: 9

语言:HTML

类型:craft-plugin

1.0.5 2018-02-26 10:02 UTC

This package is not auto-updated.

Last update: 2019-11-16 17:15:41 UTC


README

icon

Craft CMS 3.x的MailChimp列表插件

在Craft中创建、管理和监控您的MailChimp列表。

Screenshot

要求

此插件需要Craft CMS 3.0.0-RC11或更高版本。

安装

要安装插件,请按照以下说明操作。

  1. 打开您的终端并进入Craft项目目录

     cd /path/to/project
    
  2. 然后告诉Composer加载插件

     composer require lukeyouell/craft-mailchimplists
    
  3. 在控制面板中,转到设置→插件,并点击MailChimp Lists的“安装”按钮。

配置MailChimp列表

您需要提供一个MailChimp API密钥,该密钥用于获取相关数据中心并验证请求。

您的API密钥在此处可用.

需要MailChimp账户,如果您还没有,请点击此处创建一个

提供免费和付费计划。

使用MailChimp列表

一旦您向插件提供了MailChimp API密钥,您将能够直接从Craft中创建、管理和监控您的列表。

示例表单

您的列表订阅表单模板应该看起来像这样

<form method="post" action="" accept-charset="UTF-8">

  {{ csrfInput() }}
  <input type="hidden" name="action" value="mailchimp-lists/subscribe">
  <input type="hidden" name="redirect" value="{{ 'foo/bar'|hash }}">
  <input type="hidden" name="listId" value="{{ 't74m4dbg9r'|hash }}">
  <input type="hidden" name="status" value="{{ 'subscribed'|hash }}">
  
  <label>Email Address</label>
  <input type="email" name="email_address" placeholder="joe.bloggs@email.com">
  
  <label>First Name</label>
  <input type="text" name="merge_fields[FNAME]" placeholder="Joe">
  
  <label>Last Name</label>
  <input type="text" name="merge_fields[LNAME]" placeholder="Bloggs">
  
  <input type="submit" value="Subscribe">
            
</form>

表单参数

名称 必填 已散列 预期值
listId 列表的唯一ID
状态 subscribedunsubscribedcleanedpending
email_address 订阅者的电子邮件地址
email_type htmltext
merge_fields[] 成员的合并变量和值
interests[] 此字段的名称是相关兴趣的ID
language 如果设置/检测到,则订阅者的语言ISO 3166国家代码
vip 订阅者的VIP状态
location[latitude] 订阅者位置的纬度
location[longitude] 订阅者位置的经度

上述字段名称是区分大小写的

提交后重定向

如果您有一个隐藏的redirect输入,则在成功提交后,用户将被重定向到该输入。这也必须是一个散列值。

如果您没有隐藏的redirect输入,则插件将返回json(方便调试)

Ajax 提交

如果您愿意,可以选择通过 Ajax 提交。只需向您的网站发送一个 POST 请求,包含所有通常要发送的数据(除了 redirect 字段)

$('form').submit(function(ev) {
  // Prevent the form from actually submitting
  ev.preventDefault();

  // Send it to the server
  $.post({
    url: '/',
    dataType: 'json',
    data: $(this).serialize(),
    success: function(response) {
      if (response.success && response.statusCode == 200) {
        alert('Success!');
      } else if (response.statusCode !== 200) {
        alert('MailChimp error: ' + response.body.title)
      } else {
        alert('An error occurred. Please try again.');
      }
    }
  });
});

示例响应

成功

{
   "success": true,
   "statusCode": 200,
   "reason": "OK",
   "body": {
      "id": "24d2b4y97c4fe95a2d6a3d3ba2018cb0",
      "email_address": "joe.bloggs@email.com",
      "unique_email_id": "84a5q243cd",
      "email_type": "html",
      "status": "subscribed",
      "merge_fields": {
         "FNAME": "Joe",
         "LNAME": "Bloggs",
      },
      "stats": {
         "avg_open_rate": 0,
         "avg_click_rate": 0
      },
      "ip_signup": "",
      "timestamp_signup": "",
      "ip_opt": "8.8.8.8",
      "timestamp_opt": "2018-02-21T13:37:36+00:00",
      "member_rating": 2,
      "last_changed": "2018-02-21T13:37:36+00:00",
      "language": "",
      "vip": false,
      "email_client": "",
      "location": {
         "latitude": 0,
         "longitude": 0,
         "gmtoff": 0,
         "dstoff": 0,
         "country_code": "",
         "timezone": ""
      },
      "list_id": "t74m4dbg9r"
   }
}

MailChimp 错误

{
   "success": true,
   "statusCode": 400,
   "reason": "Bad Request",
   "body": {
      "type": "http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
      "title": "Member Exists",
      "status": 400,
      "detail": "joe.bloggs@email.com is already a list member. Use PUT to insert or update list members.",
      "instance": "a6d8eac9-3456-123a-a01b-22r4342d6432"
   }
}

请求失败

{
   "success": false,
   "reason": "cURL error 6: Could not resolve host: us17.api.mailchimp.co.uk (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)"
}

覆盖插件设置

如果您在配置文件夹中创建了一个名为 mailchimp-lists.php配置文件,您可以覆盖控制面板中的插件设置。由于该配置文件完全 支持多环境,这是一种在不同环境中使用不同设置的好方法。

以下是该配置文件可能的样子,以及您可以覆盖的所有可能值。

<?php

return [
    'apiKey' => '',
];

MailChimp 列表路线图

一些要完成的事情,以及潜在功能的想法

  • 列表增长
  • 编辑成员
  • 成员活动
  • 按日期排序成员
  • 仪表板小部件
  • 自定义进度条参数

Luke Youell 提供