Passing Custom fields on click view???

When I review a click report through the API I can see the basic information in a table. Email address, CITY, REGION, etc. I'd like to also view things like the TELEPHONE, FIRST NAME, LAST NAME. Here is the code I have (I've tried echo $click->FIRSTNAME, this does not work).

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

require_once('auth.php');

$api_key = $_SESSION['api_key'];
$campaign_id = $_GET['campaign'];

require_once ('wrapper/csrest_campaigns.php');

$wrap = new CS_REST_Campaigns($campaign_id, $api_key);
//$result = $wrap->get_clicks('Get clicks since', 1, 50, 'email', 'asc');
$result = $wrap->get_clicks(date('Y-m-d', strtotime('-30 days')), 1, 1000);

?>


<?PHP require_once('header.php'); ?>

<?PHP if(count($clicks) > 0): //Only display table if there's something to display! ?>
<table>
<thead>

</thead>
<tbody>

<?PHP
foreach($clicks as $click){
    echo '<tr>';

        echo '<td>';
        echo '<a href="subscriber_info.php?list='.$click->ListID.'&email='. $click->EmailAddress.'" target="_blank">'.$click->EmailAddress.'</a>';
        echo '</td>';
       
        echo '<td>';
        if($click->URL == 'Link to web-based version of this email'){
       
        if(!isset($web_version)){
       
        $campaign_summary = $wrap->get_summary();
       
        $web_version = $campaign_summary->response->WebVersionURL;
        }
       
        echo '<a href="'.$web_version.'" target="_blank">Link to web-based version of this email</a>';
        }else{
        echo '<a href="'.$click->URL.'" target="_blank">'.$click->URL.'</a>';
        }
        echo '</td>';
       
        echo '<td>';
        echo $click->City;
        echo '</td>';
       
        echo '<td>';
        echo $click->Region;
        echo '</td>';
       
        echo '<td>';
        echo $click->CountryCode;
        echo '</td>';
       
        echo '<td>';
        echo $click->ListID;
        echo '</td>';
       
        echo '<td>';
        echo $Company;
        echo '</td>';
       
        echo '<td>';
        echo $click->Date;
        echo '</td>';
       
        echo '<td>';
        echo '<a href="http://infosniper.net/?ip_address='.$click->IPAddress.'" target="_blank">'.$click->IPAddress.'</a>';
        echo '</td>';   
   
    echo '</tr>';
}
?>

</tbody>
</table>
<?PHP endif; //Only display table if there's something to display! ?>

<?PHP

if(count($clicks) < 1){
echo 'No one clicked!';
}

?>

<?PHP require_once('footer.php'); ?>

Phil Phil, 2 years ago

Hi OneLDesigns,

Have you tried looking at the API documentation? The php library is only a very thin wrapper around the REST API, so the methods there very closely reflect the data indicated in the documentation.

In this case, you can see that the data returned when you grab the campaign clicks includes the Geo-location information (like City and Country that you've mentioned), but it doesn't include any of the custom field information associated with that email address.

To get the custom field information that you're looking for (ie Telephone), you can use the ListID and EmailAddress returned by the clicks() call, and pass it to one of two other API calls:
1. Get an individual subscribers details. That maps to this method in the php wrapper.
2. That might prove to be inefficient if you have to make a lot of individual calls. If the campaign was only sent to a couple of lists you might find it better to get all the active subscribers for each list and use the custom fields contained there. You'll find that here in the php wrapper.

Hope that helps :)

Join 200,000 companies around the world that use Campaign Monitor to run email marketing campaigns that deliver results for their business.

Get started for free
1-888-533-8098