« Back to Documentation Overview

campaignSegmentTest – v1.1

 campaignSegmentTest(string apikey, string list_id, array options)

Allows one to test their segmentation rules before creating a campaign using them

Section
Campaign Related
Parameters
apikey a valid API Key for your user account. Get by calling Get by visiting your API dashboard
list_id the list to test segmentation on - get lists using lists()
options with 2 keys:
string"match"controls whether to use AND or OR when applying your options - expects "any" (for OR) or "all" (for AND)
array"conditions"- up to 10 different criteria to apply while segmenting. Each criteria row should contain 3 keys - "field", "op", or "value" based on these definitions:
 
Field = "date" : Select based on various dates we track
Valid Op(eration): eq (is) / gt (after) / lt (before)
Valid Values:
stringlast_campaign_sentuses the date of the last campaign sent
stringcampaign_id- uses the send date of the campaign that carriers the Id submitted - see campaigns()
stringYYYY-MM-DD- ny date in the form of YYYY-MM-DD - note: anything that appears to start with YYYY will be treated as a date
 
Field = "interests":
Valid Op(erations): one / none / all
Valid Values: a comma delimited of interest groups for the list - see listInterestGroups()
 
Field = "aim"
Valid Op(erations): open / noopen / click / noclick
Valid Values: "any" or a valid AIM-enabled Campaign that has been sent
 
Default Field = A Merge Var. Use Merge0-Merge15 or the Custom Tag you've setup for your merge field - see listMergeVars()
Valid Op(erations):
eq (=)/ne(!=)/gt(>)/lt(<)/like(like '%blah%')/nlike(not like '%blah%')/starts(like 'blah%')/ends(like '%blah')
Valid Values: any string
Returns
integer total The total number of subscribers matching your segmentation options

Examples (2)

download example code

[1] mcapi_campaignSegmentTest.php

  1. <?php
  2. /**
  3. This Example shows how to test a List Segment for use with a new campaign
  4. via the MCAPI class.
  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. $conditions = array();
  12. $conditions[] = array('field'=>'email', 'op'=>'like', 'value'=>'mailchimp');
  13. $opts = array('match'=>'all', 'conditions'=>$conditions);
  14.  
  15. $retval = $api->campaignSegmentTest($listId, $opts );
  16.  
  17. if ($api->errorCode){
  18. echo "Unable to Segment Campaign!";
  19. echo "\n\tCode=".$api->errorCode;
  20. echo "\n\tMsg=".$api->errorMessage."\n";
  21. } else {
  22. echo "Your Segement matched [".$retval."] members.\n";
  23. }
  24.  

[2] xml-rpc_campaignSegmentTest.php

  1. <?php
  2. /**
  3. This Example shows how to test a List Segment for use with a new campaign using
  4. XML-RPC.
  5. Note that we are using the PEAR XML-RPC2 client and recommend others do as well.
  6. **/
  7. require_once 'XML/RPC2/Client.php';
  8. require_once 'inc/config.inc.php';
  9. try {
  10. $client = XML_RPC2_Client::create($apiUrl);
  11.  
  12. $conditions = array();
  13. $conditions[] = array('field'=>'email', 'op'=>'like', 'value'=>'mailchimp');
  14. $opts = array('match'=>'all', 'conditions'=>$conditions);
  15.  
  16. $result = $client->campaignSegmentTest($apikey, $listId, $opts );
  17. echo "SUCCESS! \n";
  18. echo "Your segment matched ".$result." list members\n";
  19.  
  20. } catch (XML_RPC2_FaultException $e){
  21. echo "ERROR!!!!\n";
  22. echo $e->getFaultCode()." : ".$e->getFaultString()."\n";
  23. }
  24. echo "\n";
  25.  
  26.  
  27.