Overview

Namespaces

  • Ctct
    • Auth
    • Components
      • Account
      • Activities
      • Contacts
      • EmailMarketing
      • Tracking
    • Exceptions
    • Services
  • PHP

Classes

  • AccountService
  • ActivityService
  • BaseService
  • CampaignScheduleService
  • CampaignTrackingService
  • ContactService
  • ContactTrackingService
  • EmailMarketingService
  • ListService
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: namespace Ctct\Services;
  3: 
  4: use Ctct\Util\RestClient;
  5: use Ctct\Util\Config;
  6: use Ctct\Components\Tracking\BounceActivity;
  7: use Ctct\Components\Tracking\TrackingActivity;
  8: use Ctct\Components\Tracking\ClickActivity;
  9: use Ctct\Components\Tracking\ForwardActivity;
 10: use Ctct\Components\Tracking\OpenActivity;
 11: use Ctct\Components\Tracking\OptOutActivity;
 12: use Ctct\Components\Tracking\SendActivity;
 13: use Ctct\Components\Tracking\TrackingSummary;
 14: use Ctct\Components\ResultSet;
 15: 
 16: /**
 17:  * Performs all actions pertaining to Contact Tracking
 18:  *
 19:  * @package     Services
 20:  * @author         Constant Contact
 21:  */
 22: class ContactTrackingService extends BaseService
 23: {
 24: 
 25:     /**
 26:      * Get bounces for a given contact
 27:      * @param string $accessToken - Constant Contact OAuth2 access token
 28:      * @param int $contact_id - Contact id
 29:      * @param array $param - query params to be appended to request
 30:      * @return ResultSet - Containing a results array of {@link BounceActivity}
 31:      */
 32:     public function getBounces($accessToken, $contact_id, Array $params = null)
 33:     {
 34:         $baseUrl = Config::get('endpoints.base_url') .
 35:             sprintf(Config::get('endpoints.contact_tracking_bounces'), $contact_id);
 36: 
 37:         $url = $this->buildUrl($baseUrl, $params);
 38: 
 39:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
 40:         $body = json_decode($response->body, true);
 41: 
 42:         $bounces = array();
 43:         foreach ($body['results'] as $bounceActivity) {
 44:             $bounces[] = BounceActivity::create($bounceActivity);
 45:         }
 46: 
 47:         return new ResultSet($bounces, $body['meta']);
 48:     }
 49: 
 50:     /**
 51:      * Get clicks for a given contact
 52:      * @param string $accessToken - Constant Contact OAuth2 access token
 53:      * @param int $contact_id - Contact id
 54:      * @param array $param - query params to be appended to request
 55:      * @return ResultSet - Containing a results array of {@link ClickActivity}
 56:      */
 57:     public function getClicks($accessToken, $contact_id, Array $params = null)
 58:     {
 59:         $baseUrl = Config::get('endpoints.base_url') .
 60:             sprintf(Config::get('endpoints.contact_tracking_clicks'), $contact_id);
 61:         
 62:         $url = $this->buildUrl($baseUrl, $params);
 63: 
 64:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
 65:         $body = json_decode($response->body, true);
 66: 
 67:         $clicks = array();
 68:         foreach ($body['results'] as $click_activity) {
 69:             $clicks[] = ClickActivity::create($click_activity);
 70:         }
 71: 
 72:         return new ResultSet($clicks, $body['meta']);
 73:     }
 74: 
 75:     /**
 76:      * Get forwards for a given contact
 77:      * @param string $accessToken - Constant Contact OAuth2 access token
 78:      * @param int $contact_id - Contact id
 79:      * @param array $param - query params to be appended to request
 80:      * @return ResultSet - Containing a results array of {@link ForwardActivity}
 81:      */
 82:     public function getForwards($accessToken, $contact_id, Array $params = null)
 83:     {
 84:         $baseUrl = Config::get('endpoints.base_url') .
 85:             sprintf(Config::get('endpoints.contact_tracking_forwards'), $contact_id);
 86:         
 87:         $url = $this->buildUrl($baseUrl, $params);
 88: 
 89:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
 90:         $body = json_decode($response->body, true);
 91:         $forwards = array();
 92:         foreach ($body['results'] as $forward_activity) {
 93:             $forwards[] = ForwardActivity::create($forward_activity);
 94:         }
 95: 
 96:         return new ResultSet($forwards, $body['meta']);
 97:     }
 98: 
 99:     /**
100:      * Get opens for a given contact
101:      * @param string $accessToken - Constant Contact OAuth2 access token
102:      * @param int $contact_id - Contact id
103:      * @param array $param - query params to be appended to request
104:      * @return ResultSet - Containing a results array of {@link OpenActivity}
105:      */
106:     public function getOpens($accessToken, $contact_id, Array $params = null)
107:     {
108:         $baseUrl = Config::get('endpoints.base_url') .
109:             sprintf(Config::get('endpoints.contact_tracking_opens'), $contact_id);
110:         
111:         $url = $this->buildUrl($baseUrl, $params);
112: 
113:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
114:         $body = json_decode($response->body, true);
115:         $opens = array();
116:         foreach ($body['results'] as $open_activity) {
117:             $opens[] = OpenActivity::create($open_activity);
118:         }
119: 
120:         return new ResultSet($opens, $body['meta']);
121:     }
122: 
123:     /**
124:      * Get sends for a given contact
125:      * @param string $accessToken - Constant Contact OAuth2 access token
126:      * @param string $accessToken - Constant Contact OAuth2 access token
127:      * @param int $contact_id - Contact id
128:      * @param array $param - query params to be appended to request
129:      * @return ResultSet - Containing a results array of {@link SendActivity}
130:      */
131:     public function getSends($accessToken, $contact_id, Array $params = null)
132:     {
133:         $baseUrl = Config::get('endpoints.base_url') .
134:             sprintf(Config::get('endpoints.contact_tracking_sends'), $contact_id);
135:         
136:         $url = $this->buildUrl($baseUrl, $params);
137: 
138:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
139:         $body = json_decode($response->body, true);
140:         $sends = array();
141:         foreach ($body['results'] as $send_activity) {
142:             $sends[] = SendActivity::create($send_activity);
143:         }
144: 
145:         return new ResultSet($sends, $body['meta']);
146:     }
147: 
148:     /**
149:      * Get unsubscribes for a given contact
150:      * @param string $accessToken - Constant Contact OAuth2 access token
151:      * @param int $contact_id - Contact id
152:      * @param array $param - query params to be appended to request
153:      * @return ResultSet - Containing a results array of {@link OptOutActivity}
154:      */
155:     public function getUnsubscribes($accessToken, $contact_id, Array $params = null)
156:     {
157:         $baseUrl = Config::get('endpoints.base_url') .
158:             sprintf(Config::get('endpoints.contact_tracking_unsubscribes'), $contact_id);
159: 
160:         $url = $this->buildUrl($baseUrl, $params);
161:        
162:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
163:         $body = json_decode($response->body, true);
164:         $opt_outs = array();
165:         foreach ($body['results'] as $opt_out_activity) {
166:             $opt_outs[] = OptOutActivity::create($opt_out_activity);
167:         }
168: 
169:         return new ResultSet($opt_outs, $body['meta']);
170:     }
171: 
172:     /**
173:      * Get a summary of reporting data for a given contact
174:      * @param string $accessToken - Constant Contact OAuth2 access token
175:      * @param int $contact_id - Contact id
176:      * @return TrackingSummary
177:      */
178:     public function getSummary($accessToken, $contact_id)
179:     {
180:         $url = Config::get('endpoints.base_url') .
181:             sprintf(Config::get('endpoints.contact_tracking_summary'), $contact_id);
182:         $response = parent::getRestClient()->get($url, parent::getHeaders($accessToken));
183:         return TrackingSummary::create(json_decode($response->body, true));
184:     }
185: }
186: 
Appconnect PHP SDK API documentation generated by ApiGen 2.8.0