GithubHelp home page GithubHelp logo

laravel-mailchimp-segment's Introduction

laravel-mailchimp-segment

Simple Laravel service for MailChimp Segments

Install

  • composer install -- make sure to add repo as repository
  • Add API key to .env file
    • MAILCHIMP_APIKEY='123344dfff-us10'
    • Must use the single quotes!
  • Add provider in config/app.php
    • In package service providers add:
    • \calderawp\mailchimp\segments\PackageServiceProvider::class

Usage

Primary usage is to add or remove emails from segments, but lower-level APIs are provided.

Working With Pre-Exsiting Segments

NOTE: $listId and $segmentId are assumed

Get emails from a segment

    //create object for segment
    $segement = \calderawp\mailchimp\segments\Factory::segment( config('mailchimp-segments.apiKey'), $listId, ) $segmentId );
    
    $emails = $segment->getEmails();

Add emails to a segment

    //create object for segment
    $segement = \calderawp\mailchimp\segments\Factory::segment( config('mailchimp-segments.apiKey'), $listId, ) $segmentId );
    
    //$emials will contain all emails in segment after update
    //Note, addresses not in list are ignored
    $emails = $segement->addEmails([
              		'[email protected]',
              		'[email protected]'
              	]);
    

Remove emails from a segment

    //create object for segment
    $segement = \calderawp\mailchimp\segments\Factory::segment( config('mailchimp-segments.apiKey'), $listId, $segmentId );
    
    //$emials will contain all emails in segment after update
    //Note, addresses not in list are ignored
    $emails = $segement->removeEmails([
              		'[email protected]',
              	]);
    

Other Examples

Create segment

    $segmentAPI = \calderawp\mailchimp\segments\Factory::segments( config('mailchimp-segments.apiKey') );
    $listId = 'f402a6993d';
    $segmentAPI->create( $listId, [
    			'[email protected]',
               '[email protected]'
    		],'Test Segment' );

Get All Segments Of A List

    $segmentAPI = \calderawp\mailchimp\segments\Factory::segments( config('mailchimp-segments.apiKey') );
    $listId = 'f402a6993d';
    $segments = $segmentAPI->segments( $listId );

Get All Segments Of All Lists For An Account

    $lists = \calderawp\mailchimp\segments\Factory::lists( config('mailchimp-segments.apiKey') );
    $ids = $lists->getListIds();
    $segments = [];
    foreach( $ids as $listId ){
        $segmentAPI = \calderawp\mailchimp\segments\Factory::segments( config('mailchimp-segments.apiKey') );
    
        $s = $segmentAPI->segments( $listId );
        $segments  = array_merge($segments, $s );
    }

License, etc.

Copyrigtht 2017 CalderaWP LLC - License: GPL V2 or later

laravel-mailchimp-segment's People

Contributors

shelob9 avatar

Watchers

James Cloos avatar  avatar Christie Chirinos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.