« Back to Documentation Overview

campaignStats – v1.3

 campaignStats(string apikey, string cid)

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

Section
Campaign Stats
Parameters
apikey a valid API Key for your user account. Get by visiting your API dashboard
cid the campaign id to pull stats for (can be gathered using campaigns())
Returns
array struct of the statistics for this campaign
intsyntax_errorsNumber of email addresses in campaign that had syntactical errors.
inthard_bouncesNumber of email addresses in campaign that hard bounced.
intsoft_bouncesNumber of email addresses in campaign that soft bounced.
intunsubscribesNumber of email addresses in campaign that unsubscribed.
intabuse_reportsNumber of email addresses in campaign that reported campaign for abuse.
intforwardsNumber of times email was forwarded to a friend.
intforwards_opensNumber of times a forwarded email was opened.
intopensNumber of times the campaign was opened.
stringlast_openDate of the last time the email was opened.
intunique_opensNumber of people who opened the campaign.
intclicksNumber of times a link in the campaign was clicked.
intunique_clicksNumber of unique recipient/click pairs for the campaign.
stringlast_clickDate of the last time a link in the email was clicked.
intusers_who_clickedNumber of unique recipients who clicked on a link in the campaign.
intemails_sentNumber of email addresses campaign was sent to.
intunique_likestotal number of unique likes (Facebook)
intrecipient_likestotal number of recipients who liked (Facebook) the campaign
intfacebook_likestotal number of likes (Facebook) that came from Facebook
arrayabsplitIf this was an absplit campaign, stats for the A and B groups will be returned
intbounces_abounces for the A group
intbounces_bbounces for the B group
intforwards_aforwards for the A group
intforwards_bforwards for the B group
intabuse_reports_aabuse reports for the A group
intabuse_reports_babuse reports for the B group
intunsubs_aunsubs for the A group
intunsubs_bunsubs for the B group
intrecipients_click_aclicks for the A group
intrecipients_click_bclicks for the B group
intforwards_opens_aopened forwards for the A group
intforwards_opens_bopened forwards for the A group
arraytimewarpIf this campaign was a Timewarp campaign, an array of stats from each timezone for it, with the GMT offset as they key. Each timezone will contain:
intopensopens for this timezone
stringlast_openthe date/time of the last open for this timezone
intunique_opensthe unique opens for this timezone
intclicksthe total clicks for this timezone
stringlast_clickthe date/time of the last click for this timezone
intunique_opensthe unique clicks for this timezone
intbouncesthe total bounces for this timezone
inttotalthe total number of members sent to in this timezone
intsentthe total number of members delivered to in this timezone
arraytimeseriesFor the first 24 hours of the campaign, per-hour stats:
stringtimestampThe timestemp in Y-m-d H:00:00 format
intemails_sentthe total emails sent during the hour
intunique_opensunique opens seen during the hour
intrecipients_clickunique clicks seen during the hour

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
  8.  
  9. $api = new MCAPI($apikey);
  10.  
  11. $retval = $api->campaignStats($campaignId);
  12.  
  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. }
  23.  
  24. ?>
  25.  

[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);
  11.  
  12. $result = $client->campaignStats($apikey, $campaignId);
  13.  
  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";
  24.  
  25. ?>
  26.