« Back to Documentation Overview

campaignStats – v1.1

 campaignStats(string apikey, string cid)

Given a list and a campaign, get all the relevant campaign statistics (opens, bounces, clicks, etc.)

Campaign Stats
apikey a valid API Key for your user account. Get by calling Get by visiting your API dashboard
cid the campaign id to pull stats for (can be gathered using campaigns())
array struct of the statistics for this campaign
Returned Fields
integersyntax_errorsNumber of email addresses in campaign that had syntactical errors.
integerhard_bouncesNumber of email addresses in campaign that hard bounced.
integersoft_bouncesNumber of email addresses in campaign that soft bounced.
integerunsubscribesNumber of email addresses in campaign that unsubscribed.
integerabuse_reportsNumber of email addresses in campaign that reported campaign for abuse.
integerforwardsNumber of times email was forwarded to a friend.
integerforwards_opensNumber of times a forwarded email was opened.
integeropensNumber of times the campaign was opened.
datelast_openDate of the last time the email was opened.
integerunique_opensNumber of people who opened the campaign.
integerclicksNumber of times a link in the campaign was clicked.
integerunique_clicksNumber of unique recipient/click pairs for the campaign.
datelast_clickDate of the last time a link in the email was clicked.
integerusers_who_clickedNumber of unique recipients who clicked on a link in the campaign.
integeremails_sentNumber of email addresses campaign was sent to.

Examples (2)

download example code

[1] mcapi_campaignStats.php

  1. <?php
  2. /**
  3. This Example shows how to pull basic stats for a Campaign Tests
  4. via the MCAPI class.
  5. **/
  6. require_once 'inc/MCAPI.class.php';
  7. require_once 'inc/config.inc.php'; //contains apikey
  9. $api = new MCAPI($apikey);
  11. $retval = $api->campaignStats($campaignId);
  13. if ($api->errorCode){
  14. echo "Unable to Load Campaign Stats!";
  15. echo "\n\tCode=".$api->errorCode;
  16. echo "\n\tMsg=".$api->errorMessage."\n";
  17. } else {
  18. echo "Stats for ".$campaignId."\n";
  19. foreach($retval as $k=>$v){
  20. echo "\t".$k." => ".$v."\n";
  21. }
  22. }

[2] xml-rpc_campaignStats.php

  1. <?php
  2. /**
  3. This Example shows how to using XML-RPC to grab the Stats for a Campaign you
  4. previously sent
  5. Note that we are using the PEAR XML-RPC client and recommend others do as well.
  6. **/
  7. require_once 'XML/RPC2/Client.php';
  8. require_once 'inc/config.inc.php';
  9. try {
  10. $client = XML_RPC2_Client::create($apiUrl);
  12. $result = $client->campaignStats($apikey, $campaignId);
  14. echo "SUCCESS! \n";
  15. echo "Stats for ".$campaignId."\n";
  16. foreach($result as $k=>$v){
  17. echo "\t".$k." => ".$v."\n";
  18. }
  19. } catch (XML_RPC2_FaultException $e){
  20. echo "ERROR!!!!\n";
  21. echo $e->getFaultCode()." : ".$e->getFaultString()."\n";
  22. }
  23. echo "\n";