campaignClickStats()

List of all the links found in campaign is obtained, as well as the number of total clicks and unique clicks.

campaignClickStats(string $cid) : struct
Input parameters
  • cid - campaign ID
Information obtained

Array of links consisting of:

  • id - link ID used in other API functions
  • url - URL address
  • clicks - number of clicks
  • unique - unique clicks

Examples

mgapi_campaignClickStats.php
<?php
/**
 * This Example shows how to campaignClickStats using the MGAPI.php class and do some basic error checking.
 */
require_once 'inc/MGAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey
 
$api = new MGAPI($apikey);
 
$cid = $campaignId;
 
$retval = $api->campaignClickStats($cid);
 
header("Content-Type: text/plain");
if ($api->errorCode) {
    echo "Unable to load campaignClickStats()!";
    echo "\tCode=" . $api->errorCode . "\n";
    echo "\tMsg=" . $api->errorMessage . "\n";
} else {
    if (sizeof($retval) == 0) {
        echo "No stats for this campaign yet!\n";
    } else {
        foreach ($retval as $url => $detail) {
            echo "Link id: {$detail['id']} - {$detail['url']}\n";
            echo "\tClicks = {$detail['clicks']}\n";
            echo "\tUnique Clicks = {$detail['unique']}\n";
        }
    }
}
xml-rpc_campaignClickStats.php
<?php
/**
 * This Example shows how execute a campaignClickStats and check the result using XML-RPC.
 * Note that we are using the PEAR XML-RPC client and recommend others do as well.
 */
require_once 'xmlrpc-3.0.0.beta/xmlrpc.inc';
require_once 'inc/config.inc.php';
 
$apiUrl = parse_url($apiUrl);
 
$v = new xmlrpcval(array(
        'apikey' => new xmlrpcval($apikey),
        'cid' => new xmlrpcval($campaignId),
        'start' => new xmlrpcval(0),
        'limit' => new xmlrpcval(1000)
    ), 'struct');
$f = new xmlrpcmsg('campaignClickStats', array($v));
$c = new xmlrpc_client($apiUrl["path"], $apiUrl['host'], 80);
$c->setDebug($debug);
$r = &$c->send($f);
 
header("Content-Type: text/plain");
if (!$r->faultCode()) {
    $retval = php_xmlrpc_decode($r->value());
    if (sizeof($stats) == 0) {
        echo "No stats for this campaign yet!\n";
    } else {
        foreach ($retval as $url => $detail) {
            echo "URL: " . $url . "\n";
            echo "\tClicks = " . $detail['clicks'] . "\n";
            echo "\tUnique Clicks = " . $detail['unique'] . "\n";
        }
    }
} else {
    echo "Unable to run campaignClickStats()!\n";
    echo "\tCode=" . $r->faultCode() . "\n";
    echo "\tMsg=" . $r->faultString() . "\n";
}
mgapi_campaignClickStats.py
from lib.config import * #contains apikey
from lib.MGAPI import MGAPI
 
# This Example shows how to ping using the MGAPI.php class and do some basic error checking.
 
api = MGAPI(apikey)
 
cid = campaignId
 
retval = api.campaignClickStats(cid)
if api.errorCode:
    print "Unable to load campaignClickStats()!"
    print "\tCode=", api.errorCode
    print "\tMsg=", api.errorMessage
else:
    if len(retval) == 0:
        print "No stats for this campaign yet!"
    else:
        for url, detail in retval.items():
            print "URL: %s" % (url)
            print "\tClicks = %s" % (detail['clicks'])
            print "\tUnique Clicks = %s" % (detail['unique'])

© 2010-2018 Mailigen. All rights reserved.