« Back to Documentation Overview

campaignAnalytics – v1.3

 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.
intvisitsnumber of visits
intpagesnumber of page views
intnew_visitsnew visits recorded
intbouncesvistors who "bounced" from your site
doubletime_on_sitethe total time visitors spent on your sites
intgoal_conversionsnumber of goals converted
doublegoal_valuevalue of conversion in dollars
doublerevenuerevenue generated by campaign
inttransactionsnumber of transactions tracked
intecomm_conversionsnumber Ecommerce transactions tracked
arraygoalsan array containing goal names and number of conversions
stringnamethe name of the goal
intconversionsthe number of conversions for the goal

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.