« Back to Documentation Overview

campaignClickStats – v1.1

 campaignClickStats(string apikey, string cid)

Get an array of the urls being tracked, and their click counts for a given campaign

Section
Campaign Stats
Parameters
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())
Returns
struct urls will be keys and contain their associated statistics:
Returned Fields
integerclicksNumber of times the specific link was clicked
integeruniqueNumber of unique people who clicked on the specific link

Examples (2)

download example code

[1] mcapi_campaignClickStats.php

  1. <?php
  2. /**
  3. This Example shows how to pull and iterate through a campaignClickStats call via
  4. using the MCAPI wrapper 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. $stats = $api->campaignClickStats($campaignId);
  12. if ($api->errorCode){
  13. echo "Unable to load campaignClickStats()!\n\t";
  14. echo "Code=".$api->errorCode."\n\t";
  15. echo "Msg=".$api->errorMessage."\n";
  16. } else {
  17. if (sizeof($stats)==0){
  18. echo "No stats for this campaign yet!\n";
  19. } else {
  20. foreach($stats as $url=>$detail){
  21. echo "URL: ".$url."\n";
  22. echo "\tClicks = ".$detail['clicks']."\n";
  23. echo "\tUnique Clicks = ".$detail['unique']."\n";
  24. }
  25. }
  26. }
  27.  
  28. ?>
  29.  

[2] xml-rpc_campaignClickStats.php

  1. <?php
  2. /**
  3. This Example shows how to iterate through a campaignClickStats call using XML-RPC.
  4. Note that we are using the PEAR XML-RPC client and recommend others do as well.
  5. **/
  6. require_once 'XML/RPC2/Client.php';
  7. require_once 'inc/config.inc.php';
  8. try {
  9. $client = XML_RPC2_Client::create($apiUrl);
  10.  
  11. $result = $client->campaignClickStats($apikey, $campaignId);
  12. echo "SUCCESS! \n";
  13. foreach($result as $url=>$stats){
  14. echo "URL: ".$url."\n";
  15. echo "Clicks = ".$stats['clicks']." Unique Clicks = ".$stats['unique']."\n";
  16. }
  17. } catch (XML_RPC2_FaultException $e){
  18. echo "ERROR!!!!\n";
  19. echo $e->getFaultCode()." : ".$e->getFaultString()."\n";
  20. }
  21.  
  22.