Echoing number of CM subscribers on WordPress web site

Hello there

I posted the following message else:

Fairly new to CM so apologies if my question is frequently asked. I've had a search and not been able to find anything concrete with regards to my query.

I have used the Contact Form 7 WordPress plugin addon to successfully link my list to my web site using the API. The next thing I would like to do is echo the number of people who have signed up somewhere on my page. To do this, I assume I need to use the Subscribers.GetActive function, but I have no idea how to do it.

API info link: http://www.campaignmonitor.com/api/meth … getactive/

Is it simply a case of embedding the XML in my page somehow?

Thanks in advance,
James

[ http://www.campaignmonitor.com/forums/viewtopic.php?pid=16423#p16423 ]

I would like to include the data using PHP.

As you can see I was told in reply to that topic that I should post here and consider using List.GetStats. Any information on how I can simply echo the number of subscribers on my page would be most appreciated - am slightly against it time-wise!

Thanks,
James

jamblo, 6 years ago

OK, progress!

Using

<?php

ini_set ('display_errors', 1);
error_reporting (E_ALL);

require_once('CMBase.php');

//-----------------------------INPUT PARAMS---------------------------------------

$apikey = 'XXXX';
$listid = 'XXXX';        

//-------------------------------------------------------------------------------    
    
    $cm = new CampaignMonitor( $apikey );
    
    //Optional statement to include debugging information in the result
    $cm->debug_level = 1;
    
    //This is the actual call to the method
    $result = $cm->listGetDetail( $listid );
    
    echo '';
//    print_r($result);
    print_r($cm->listGetStats( $listid ));

    
?>

I get the following result:

Array ( [anyType] => Array ( [TotalActiveSubscribers] => 3 [NewActiveSubscribersToday] => 0 [NewActiveSubscribersYesterday] => 3 [NewActiveSubscribersThisWeek] => 3 [NewActiveSubscribersThisMonth] => 3 [NewActiveSubscribersThisYear] => 3 [TotalUnsubscribes] => 0 [UnsubscribesToday] => 0 [UnsubscribesYesterday] => 0 [UnsubscribesThisWeek] => 0 [UnsubscribesThisMonth] => 0 [UnsubscribesThisYear] => 0 [TotalDeleted] => 0 [DeletedToday] => 0 [DeletedYesterday] => 0 [DeletedThisWeek] => 0 [DeletedThisMonth] => 0 [DeletedThisYear] => 0 [TotalBounces] => 0 [BouncesToday] => 0 [BouncesYesterday] => 0 [BouncesThisWeek] => 0 [BouncesThisMonth] => 0 [BouncesThisYear] => 0 ) )

Now, all I want to display is the number for TotalActiveSubscribers. How do I do this?

I tried

print_r($cm->TotalActiveSubscribers());

and a number of variations but got errors.

Thanks!

jamblo, 6 years ago

Simplified:

<?php

ini_set ('display_errors', 1);
error_reporting (E_ALL);

require_once('CMBase.php');

//-----------------------------INPUT PARAMS---------------------------------------

$apikey = 'XXXX';
$listid = 'XXXX';        

//-------------------------------------------------------------------------------    
    
    $cm = new CampaignMonitor( $apikey );
    
    //Optional statement to include debugging information in the result
    $cm->debug_level = 1;
    
    //This is the actual call to the method
    $result = $cm->listGetStats( $listid );
    
    echo '';
    print_r($result);
    
?>

Still no luck printing JUST the TotalActiveSubscribers array though.

Help!

nbsp, 6 years ago

Looks like the results are in an array (so there's an extra array there), try this:

    $result = $cm->listGetStats( $listid );
    $subResult = $result['anyType'];

    echo $subResult['TotalActiveSubscribers'];

obviously modifying it or tidying as you see fit :)

nbsp;

jamblo, 6 years ago

nbsp, you are a wizard! You wouldn't believe how long I spent trying to work that out.

Thank you very, very much!

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