diff --git a/README.md b/README.md index 3c018f9..502a6ff 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Adding subscriptions requires a List ID and an email, but there are a few other * name * array of custom fields (eg `{age: 22}`) * boolean for whether to resubscribe addresses that have previously been removed (default true) +* whether the subscriber has given permission to have their email opens and clicks tracked. Values: 'Yes', 'No' or 'Unchanged' (default) Note about the **list ID**: this is _not_ the parameter "listID" in the URL when viewing a list. Annoyingly, Campaign Monitor uses two IDs for lists. To find your List ID, view [this FAQ](https://createform.com/support/campaignmonitor-list). @@ -65,6 +66,8 @@ The easiest way to add subscribers is by posting a form with their data. This fo + + @@ -100,7 +103,8 @@ Add additional parameters as needed: {% set name = 'Steve' %} {% set customFields = {age: 22, city: 'Chicago'} %} {% set resubscribe = false %} -{% craft.oneCampaignMonitor.subscribe(listId, email, name, customFields, resubscribe) %} +{% set consenttotrack = 'Yes' %} +{% craft.oneCampaignMonitor.subscribe(listId, email, name, customFields, resubscribe, consenttotrack) %} ``` ### Service (in controllers, etc) diff --git a/controllers/OneCampaignMonitor_SubscribersController.php b/controllers/OneCampaignMonitor_SubscribersController.php index 9fe10d5..82828e6 100644 --- a/controllers/OneCampaignMonitor_SubscribersController.php +++ b/controllers/OneCampaignMonitor_SubscribersController.php @@ -16,10 +16,11 @@ public function actionAdd() { $name = craft()->request->getParam('name') ?: ''; $customFields = craft()->request->getParam('customFields') ?: array(); $resubscribe = craft()->request->getParam('resubscribe') ?: true; + $consenttotrack = craft()->request->getParam('consenttotrack') ?: 'Unchanged'; $error = null; try { - craft()->oneCampaignMonitor_subscribers->add($listId, $email, $name, $customFields, $resubscribe); + craft()->oneCampaignMonitor_subscribers->add($listId, $email, $name, $customFields, $resubscribe, $consenttotrack); } catch (Exception $e) { OneCampaignMonitorPlugin::log($e->getMessage(), LogLevel::Error); $error = $e->getMessage(); diff --git a/services/OneCampaignMonitor_SubscribersService.php b/services/OneCampaignMonitor_SubscribersService.php index 66fa8f5..382f818 100644 --- a/services/OneCampaignMonitor_SubscribersService.php +++ b/services/OneCampaignMonitor_SubscribersService.php @@ -15,7 +15,7 @@ class OneCampaignMonitor_SubscribersService extends OneCampaignMonitor_BaseServi * @param $merge * @throws Exception */ - public function add($listId, $email, $name=null, $customFields=array(), $resubscribe=true) { + public function add($listId, $email, $name=null, $customFields=array(), $resubscribe=true, $consenttotrack='Unchanged') { if (!$listId) { throw new Exception('List ID is required'); } @@ -28,7 +28,8 @@ public function add($listId, $email, $name=null, $customFields=array(), $resubsc 'EmailAddress' => $email, 'Name' => $name, 'CustomFields' => $this->parseCustomFields($customFields), - 'Resubscribe' => $resubscribe + 'Resubscribe' => $resubscribe, + 'ConsentToTrack' => $consenttotrack ]); $error = null; @@ -57,7 +58,7 @@ public function exists($listId, $email) { $connection = new \CS_REST_Subscribers($listId, $this->auth()); $result = $connection->get($email); - + $error = null; return $this->response($result, $error); } @@ -81,7 +82,7 @@ public function update($listId, $email, $name=null, $customFields=array(), $resu } $connection = new \CS_REST_Subscribers($listId, $this->auth()); - + $subscriber = [ 'Resubscribe' => $resubscribe ]; @@ -94,7 +95,7 @@ public function update($listId, $email, $name=null, $customFields=array(), $resu if ($mergeMultiFields) { $result = $connection->get($email); - + $error = null; if (!$this->response($result, $error)) { throw new Exception($error); @@ -132,11 +133,11 @@ public function addOrUpdate($listId, $email, $name=null, $customFields=array(), if (!empty($customFields)) { craft()->oneCampaignMonitor_lists->ensureCustomFieldsExist($listId, $customFields); } - + if ($this->exists($listId, $email)) { return $this->update($listId, $email, $name, $customFields, $resubscribe, $mergeMultiFields); } else { return $this->add($listId, $email, $name, $customFields); - } + } } } diff --git a/variables/OneCampaignMonitorVariable.php b/variables/OneCampaignMonitorVariable.php index 3ea587c..b67913a 100644 --- a/variables/OneCampaignMonitorVariable.php +++ b/variables/OneCampaignMonitorVariable.php @@ -2,8 +2,8 @@ namespace Craft; class OneCampaignMonitorVariable { - public function subscribe($list_id, $email, $name=null, $customFields=array(), $resubscribe=true) { - return craft()->oneCampaignMonitor_subscribers->add($list_id, $email, $name, $customFields, $resubscribe); + public function subscribe($list_id, $email, $name=null, $customFields=array(), $resubscribe=true, $consenttotrack='Unchanged') { + return craft()->oneCampaignMonitor_subscribers->add($list_id, $email, $name, $customFields, $resubscribe, $consenttotrack); } public function hasSubscribed($listId) {