Published
Wednesday, March 4, 2015 - 17:50
Written by

First blog post here. I am hoping to at least shed some light on an issue I had when setting up CivicCRM. Its not a comprehensive solution to the problem; I hope to follow up soon with full source code.

Drip campaigns are a series of contacts triggered by certain event. There are many reasons to this. It is an effective way to keep in contact with a supporter over a period of time.

For example, when a user opts into an email list, you may want to send them welcome emails. These would be automated to send after 1 day, 1 week, and 1 month to remind them about your organization. For nonprofits, these emails are an effective tool to turn new prospects into donors or soliciting donors during a fund-raising campaign.

Looking through CiviCRM, this type of marketing (at least as of v4.5.5) was not explicitly supported out of the box. All necessary components were there though. There was mass mailing with granular control of recipients and scheduled reminders has a number of hooks that would run on a recurring basis.

The specific implementation I was looking to create was a "welcome series". After a potential supporters filled out a lead form, I wanted a series of emails to be triggered. These emails would go out every couple days and encourage the supported to contribute to the organization. Obviously, this required the scheduled reminder crontab to be setup. I set this to run once per day.

After messing with a couple different scheduled reminder hooks, I decided my best option was to use the membership creation hook. When selecting this hook, I was able to choose the to send the email x number of days/weeks/months after a membership was created. I was not able to use the hours option because membership creation dates do not include time in the database.

I created a free membership type that lasted for 1 lifetime to work with this setup. The next step was to create a lead form. All I was submitting was an email, so created this totally custom using the CiviCRM APIv3. 

Form (abridged version):

<form action="https://civicrm.org/%7Bsubmit%20page%7D" method="get">
    <div class="input-group">
        <input name="chemail" type="email" class="form-control" placeholder="Email..." required>
        <span class="input-group-btn">
            <button class="btn btn-primary" type="submit">Subscribe</button>
        </span>
    </div>
</form>

Submit script (abridged version):

<?php
try {
    
    // create new contacct
    $contact = civicrm_api3('Contact','create',array(
        'contact_type' => 'individual',
        'dupe_check' => '1',
        'email' => $email,
        'options' => array(
            'match' => 'email',
        ),
    ));
    
    $membership = civicrm_api3('Membership','create',array(
        'contact_id' => $contact['id'],
        'membership_type_id' => {id of free membership type},
        'status_id' => {status id of new membership},
    ));
    
} catch (Exception $e) {
            
    $return['is_error'] = 1;
    $return['error_message'] = $e->getMessage();
 
}
?>

Comments

So basically, you're using the custom code to generate memberships, and then using the regular scheduled reminders features for sending the emails.  It's novel to use memberships, and some might not want the overhead of that, but the principle is good.

An alternative some of our clients use is to have an activity instead.  In Drupal, Webform can create an activity when someone signs up, and then you just trigger the emails off that activity date in basically the same way.

Ultimately, I think it would be valuable to have reminders triggered by group subscriptions: that would be the most natural in concept, and it would mean you wouldn't have to do this custom code.

I am currently working in Joomla, so a Webform is not be an option.

Group subscription would be optimal, but I was unable to find a trigger in Scheduled Reminders that worked that way.

 

The 'Schedule Reminder' functionlaity has great potential. at present it is constrained in that there are only a few trigger events available. It would be great if we could trigger reminders based on the date a contact was tagged  with a specific tag or added to a particular group, or submitted a given profile, etc. Perhaps that will come in a future version (I certainly hope so).

I know that CiviCoop is currently working on a CiviRules project which may also be of huge benefit in this context.

I am with you, group membership date would be optimal, but there wasn't a trigger I could find for it.

We've also tended to use scheduled reminders, adding custom code to add triggers if necessary, and other custom code to ensure that needed tokens from all relevant objects (registrations, memberships, special related contacts) are made available when rendering the emails.

I've been thinking about this topic too, thanks for doing some work on it.

It also seemed to me that most of the tools needed are already in place, there just needs to be an interface that allows regular users to set up a sequence of actions for the campaign to take.

One thing that would really be helpful would be a new action that was created whenever someone viewed a particular web page.  I would think this could be tracked by including the contact checksum as a parameter in a URL(?).

For example, if someone visits a cms page: http://mysite.org/weneedmoneynow?checksum=slkdfjiufy87987g798f6g an activity would be created called "Page Visit" and a new scheduled reminder could then send a solicitation to the contact (say) 3 days after the visit.

I was not really satisfied with the current set of triggers either. Optimally, I wanted an email opt-in or contact create hook.

I really like the idea of page visits. That would be something pretty neat.