« Back to Documentation Overview

campaignAnalytics – v1.2

 campaignAnalytics(string apikey, string cid)

Retrieve the Google Analytics data we've collected for this campaign. Note, requires Google Analytics Add-on to be installed and configured.

Section
Campaign Stats
mcapi_campaignAnalytics.php
Parameters
apikey a valid API Key for your user account. Get by visiting your API dashboard
cid the campaign id to pull bounces for (can be gathered using campaigns())
Returns
array analytics we've collected for the passed campaign.
Returned Fields
integervisitsnumber of visits
integerpagesnumber of page views
integernew_visitsnew visits recorded
integerbouncesvistors who "bounced" from your site
doubletime_on_sitethe total time visitors spent on your sites
integergoal_conversionsnumber of goals converted
doublegoal_valuevalue of conversion in dollars
doublerevenuerevenue generated by campaign
integertransactionsnumber of transactions tracked
integerecomm_conversionsnumber Ecommerce transactions tracked
arraygoalsan array containing goal names and number of conversions

Examples (1)

download example code

[1] mcapi_campaignAnalytics.php

  1. <?php
  2. /**
  3. This Example shows how to retrieve Analytics data collected for a campaign with
  4. some basic error checking.
  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->campaignAnalytics($campaignId);
  12.  
  13. if ($api->errorCode){
  14. echo "Unable to run campaignAnalytics()!\n";
  15. echo "\tCode=".$api->errorCode."\n";
  16. echo "\tMsg=".$api->errorMessage."\n";
  17. } else {
  18. echo "Visits: ".$stat['visits']."\n";
  19. echo "Pages: ".$rpt['pages']."\n";
  20. echo "Goals ".$rpt['type']."\n";
  21. if ($stat['goals']){
  22. foreach($stat['goals'] as $goal){
  23. echo "\t".$goal['name']." => ".$goal['conversions']."\n";
  24. }
  25. }
  26. }
  27. ?>
  28.