Lead Tracker

Contrib type: 
Module
Status: 
approved

Downloads

Compatibility: 
Ubercart 1.x

This modules defines a checkout pane that lets customers specify how they heard about your site (and so functions as a very basic lead tracker). The pane is titled Customer Service Information and is turned on by default.

This is a demo module showing people a simple way to add a checkout pane, save and load the data collected to orders, and display the collected data on the order view screen. Presentation on the order screen is very basic, and there is currently no way to modify the data in this module.

When you install this module, you should go to the Checkout panes settings page and add lead options to appear during checkout.

Developer notes:

Use this module to see example implementations of the following hooks.

  • hook_checkout_pane() - Defines a checkout pane to add the select box to the checkout form. The callback function uses the view, process, review, and settings values for $op.
  • hook_order() - This handles saving and loading data added to the order object by the checkout pane to the database. It also serves to save and load the data on the order view screen.
  • hook_order_pane() - Defines an order pane to display the customer's choice to administrators on the order view screen.
PreviewAttachmentSize
uc_lead.tar.gz2.15 KB
Shawn Conn's picture
Offline
Administrator
Joined: 08/07/2007
Juice: 920
Removing textfield

What do you think about removing the "Other source" text field unless the user selects "other source"?

-Shawn Conn: If the Name Don't Rhyme It Ain't Mine

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15459
Re: Removing textfield

Aye, would be good... a simple touch of Javascript could handle it no doubt.

kulvik's picture
Offline
Uber DonorBug FinderEarly adopter... addicted to alphas.Cool profile pic award.Internationalizationizer
Joined: 08/14/2007
Juice: 336
Re: Lead Tracker

Thanks for this Ryan. This is almost what I need. What would I have to do to get the user input appear on the admin/customer emails ? Are there any hooks to do that?

______________
Best regards,
Thomas Kulvik
Ny Media AS
www.nymedia.no

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15459
Re: Re: Lead Tracker

Hey kulvik, since the data gets saved/loaded with hook_order(), it's actually already going to be in the order object for use by your invoice templates. Dump out the array $order->lead to see the data. Smiling

399 (not verified)
399's picture
How do I get it to work on Alpha7c?

For a variety of reasons (mostly for the coupon module and the fact that we cannot have more than a few minutes of downtime for upgrade), we would like something exactly like this that works on Alpha7c. I installed it, and the following happened:

"Customer Service" appears in the list of available checkout panes.
Settings for the lead tracker does not appear.
"Customer Service" pane does not appear in checkout...
...but it DOES appear in order review.
There is now a "Sales tracking" field in the order review screen.

We don't even need the drop-down menu... just a text field that indicates where the sale came from.

What modifications need to be done?

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15459
Re: How do I get it to work on Alpha7c?

To make this compatible for 7c, I'd just compare the code in the hook function and callback function with the code in your version of uc_cart.module and uc_cart_checkout_pane.inc. There aren't a lot of changes, and they should be recognizable. Smiling

jimi089's picture
Offline
Uber Donor
Joined: 09/07/2007
Juice: 219
Re: Re: How do I get it to work on Alpha7c?

Any chance of this bad boy being update to RC1?

I had taken it off a site I had it on but haven't reenabled it since it broke.

hedgehog's picture
Offline
Joined: 10/07/2008
Juice: 14
Orders by Admin

When an order is being placed by a Store Admin, is there anywhere to put in the lead? When viewing the order I can see it says Sales Tracking: Sales lead: None specified. But I can't see the lead drop-down menu anywhere.

iajay's picture
Offline
Joined: 07/21/2008
Juice: 49
Can we have a Report

hello Ryan
Can we have a Lead wise Sale report
e.g
Lead 1 01/01/2008 31/01/2008 $1000
Lead 2 01/01/2008 31/01/2008 $1200
Lead 3 01/01/2008 31/01/2008 $1100
Lead 4 01/01/2008 31/01/2008 $9000

I hope u got this
Can u suggest me anything
Ajay

adshill's picture
Offline
Joined: 07/24/2008
Juice: 30
Mandatory

This is probably really easy but I'm a bit stuck with it. Is there a simple way I can alter the code slightly to make this function mandatory? currently users don't need to select anything but we'd like to force them to do so...

Thanks all. Smiling

zeezhao's picture
Offline
Joined: 04/23/2008
Juice: 1075
Re: Lead Tracker

You will probably need to add something like:

'#required' => 'TRUE',

in the code, where the field of interest is being constructed.

adshill's picture
Offline
Joined: 07/24/2008
Juice: 30
Thanks Zeezhao, The problem

Thanks Zeezhao,

The problem is that when I do this (I had already tried it) the "Please Select One:" option at the top of the select list is still considered to be one of the options, so it doesn't actually sort it out. In addition, it would be good that if the user selects "other" that the other textfield also becomes mandatory. If you have any ideas it would be great.

Thanks,

Adam

Alan H's picture
Offline
Joined: 11/30/2008
Juice: 15
adshill,This is what I did

adshill,

This is what I did and it is working in regards to making the first field mandatory.

      $contents['lead_source'] = array(
        '#type' => 'select',
        '#title' => t('How I Found Your Site '),
        '#options' => drupal_map_assoc($options),
        //'#default_value' => $arg1->lead['source'],
        '#required' => 'TRUE',
      );

Notice that I quoted out the default value. That does the trick.

My next task is to make the textfield for the "Other" data to be mandatory when Other is selected in the dropdown. My thinking right now is to add some script to do the evaluation at run time and switch the field to required if Other is selected. Kinda like how the Shipping Quotes field activates when you enter in State and Zip info.

Hope this helps,

Alan.

adshill's picture
Offline
Joined: 07/24/2008
Juice: 30
Hi Alan, Many thanks,

Hi Alan,

Many thanks, however I tried the code on a clean install of the module and it is still not mandatory, or at least if you leave the selection as "Please select one.." then the checkout process will still continue. The mandatory red star is there so it's obviously doing something, but its not actually forcing anyone to choose a lead.

Any ideas?

Thanks, Adam

Alan H's picture
Offline
Joined: 11/30/2008
Juice: 15
adshill, So sorry. I left

adshill,

So sorry. I left out a line of key code. Shocked

$options = array_merge(array(t('')), $options,
                             array(t('Other source')));
      $contents['lead_source'] = array(
        '#type' => 'select',
        '#title' => t('How I Found Your Site '),
        '#options' => drupal_map_assoc($options),
        //'#default_value' => $arg1->lead['source'],
  '#required' => 'TRUE',
      );

I removed the text for the default entry in the drop down list.(Where it used to say "Please select one...") I don't think I made any other modification to the code, but I will revisit it on a clean install and let you know if there is anything else.

Alan.

adshill's picture
Offline
Joined: 07/24/2008
Juice: 30
Thanks Alan

Works like a charm Smiling

hestenet's picture
Offline
Joined: 01/26/2009
Juice: 2
Tokenizing UC_lead

How would one tokenize the data collected by UC_Lead?

My end goal is to send out this info in the confirmation email sent to admins. Is there a better way of doing this?

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15459
Re: Tokenizing UC_lead

You'll need to check out the Token module's API and implement hook_token_list() and hook_token_values(). You can see some examples in the core Ubercart modules.

ttamniwdoog's picture
Offline
Joined: 10/28/2008
Juice: 63
solved?

@hedgehog, were you able to figure out how to make this editable by Store Admins?
Never added a new hook before but I think by modifying the uc_leads module and adding a custom function like

function uc_lead_pane_admin($op,$arg1) {
  switch ($op) {
    case 'edit-form':
      $form['admin_comment_field']['admin_comment'] = array(
        '#type' => 'text',
        '#description' => t('Only seen by store administrators.'),
      );
      return $form;
}

I tried this but I recieved a BSOD (Blank Screen of Drupal).
Anyone else tried to add a pane to the admin order panes?

numenor's picture
Offline
Joined: 09/25/2008
Juice: 6
Help needed - quick $50

I've tried installing Lead Tracker for Ubercart 5.x-1.5. It shows up in the 'Checkout Settings' and on the checkout but no values are transferred the the review order page and invoice. I've had a play around with it but I don't know enough to sort it.

I've attached the original code below for anyone who can quickly see what's wrong with it. I really only want a text box shown at checkout without the dropdown box, where a buyer can enter a voucher number if they have one.

If someone can help me I'll paypal them $50.

Cheers

/*******************************************************************************
* Hook Functions (Ubercart)
******************************************************************************/

/**
* Implementation of hook_checkout_pane().
*/
function uc_lead_checkout_pane() {
  $panes[] = array(
    'id' => 'lead',
    'callback' => 'uc_checkout_pane_lead',
    'title' => t('Customer Service Information'),
    'desc' => t('Find out how the customer heard about your site.'),
    'weight' => 8,
  );

  return $panes;
}

/**
* Implementation of hook_order().
*/
function uc_lead_order($op, &$arg1, $arg2) {
  switch ($op) {
    // Save the lead to the database.
    case 'save':
      if (!empty($arg1->lead['source'])) {
        db_query("UPDATE {uc_leads} SET lead_source = '%s', lead_other = '%s' "
                ."WHERE order_id = %d", $arg1->lead['source'],
                 $arg1->lead['other'], $arg1->order_id);
        if (db_affected_rows() == 0) {
          db_query("INSERT INTO {uc_leads} (lead_id, order_id, lead_source, "
                  ."lead_other) VALUES (%d, %d, '%s', '%s')",
                   db_next_id('{uc_leads}_lead_id'), $arg1->order_id,
                   $arg1->lead['source'], $arg1->lead['other']);
        }
      }
      break;

    // Load the lead from the database.
    case 'load':
      $result = db_query("SELECT * FROM {uc_leads} WHERE order_id = %d", $arg1->order_id);
      if ($data = db_fetch_object($result)) {
        $arg1->lead['source'] = $data->lead_source;
        if ($arg1->lead['source'] == t('Other source')) {
          $arg1->lead['other'] = $data->lead_other;
        }
      }
      break;

    // Delete the lead from the database.
    case 'delete':
      db_query("DELETE FROM {uc_leads} WHERE order_id = %d", $arg1->order_id);
      break;
  }
}

/**
* Implementation of hook_order_pane().
*/
function uc_lead_order_pane() {
  $panes[] = array(
    'id' => 'lead',
    'callback' => 'uc_order_pane_lead',
    'title' => t('Sales Tracking'),
    'desc' => t('See how the customer found out about your site.'),
    'class' => 'abs-left',
    'weight' => 7,
    'show' => array('view'),
  );

  return $panes;
}

/*******************************************************************************
* Callback Functions, Forms, and Tables
******************************************************************************/

function uc_checkout_pane_lead($op, &$arg1, $arg2) {
  switch ($op) {
    case 'view':
      $description = t('To better serve our customers, we would love to hear how you found us!');

      $options = preg_split('/[\r\n]+/', variable_get('uc_lead_options', ''));
      for ($i = 0; $i < count($options); $i++) {
        if (empty($options[$i])) {
          unset($options[$i]);
        }
      }
      $options = array_merge(array(t('Please select one...')), $options,
                             array(t('Other source')));
      $contents['lead_source'] = array(
        '#type' => 'select',
        '#title' => t('I found your site through'),
        '#options' => drupal_map_assoc($options),
        '#default_value' => $arg1->lead['source'],
      );
      $contents['lead_other'] = array(
        '#type' => 'textfield',
        '#title' => t('Other source'),
        '#description' => t('Fill this in if you chose <em>Other source</em> above.'),
        '#default_value' => $arg1->lead['source'] == t('Other source') ? $arg1->lead['other'] : '',
      );
      return array('description' => $description, 'contents' => $contents);

    case 'process':
      if ($arg1->lead['source'] !== t('Please select one...')) {
        $arg1->lead['source'] = $arg2['lead_source'];
      }
      if ($arg1->lead['source'] == t('Other source')) {
        $arg1->lead['other'] = $arg2['lead_other'];
      }
      return TRUE;

    case 'review':
      if ($arg1->lead['source'] != t('Please select one...')) {
        $review[] = array('title' => t('Site found through'), 'data' => $arg1->lead['source'] == t('Other source') ? check_plain($arg1->lead['other']) : check_plain($arg1->lead['source']));
      }
      return $review;

    case 'settings':
      $form['uc_lead_options'] = array(
        '#type' => 'textarea',
        '#title' => t('Lead options'),
        '#description' => t('Enter options one per line for the lead tracking select box.'),
        '#default_value' => variable_get('uc_lead_options', ''),
      );
      return $form;
  }
}

function uc_order_pane_lead($op, $arg1) {
  switch ($op) {
    case 'view':
      if (empty($arg1->lead['source'])) {
        $lead = t('None specified');
      }
      elseif ($arg1->lead['source'] == t('Other source')) {
        $lead = $arg1->lead['other'];
      }
      else {
        $lead = $arg1->lead['source'];
      }
      return t('Sales lead: @lead', array('@lead' => $lead));
  }
}

criznach@drupal.org's picture
Offline
Joined: 12/26/2007
Juice: 30
Re: Help needed - quick $50

I've contacted numenor with a possible solution.

idanarbel's picture
Offline
Joined: 08/01/2008
Juice: 115
Re: Lead Tracker

Is there a drupal 6 version of this module?

adamo's picture
Offline
Getting busy with the Ubercode.
Joined: 02/17/2009
Juice: 229
Re: Re: Lead Tracker

I'm working on a similar module called Referral Sources for UC2/D6 that will provide the same functionality that Lead Tracker does and a little bit more... In addition to the checkout/order panes it will allow you to easy place a referral source selection on the user registration/account page, any Webform, or any FAPI form, and track the data in a central location. I hope to have an initial release ready in a few days.

mkrapf's picture
Offline
Joined: 04/13/2009
Juice: 34
Adding an additional text field?

How difficult would it be to add additional text fields if the "other" option is selected?

To clarify, I would like to have three different text fields for options like name, phone, and birthdate if the "other" option is selected.

Any help would be greatly appreciated.

I'm actually using the Ubercart 2.x version http://www.ubercart.org/contrib/10185, but thought I would go to the source.

Thanks

adamo's picture
Offline
Getting busy with the Ubercode.
Joined: 02/17/2009
Juice: 229
Referral Sources

I've posted a module in contrib called Referral Sources that provides similar functionality to Lead Tracker, but allows you to embed "Where did you hear about us?" type prompts anywhere in your site (registration, checkout, webforms, any other form) and track all submission data in a central location.

See here: http://www.ubercart.org/contrib/11656

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15459
Re: Referral Sources

Awesome job, adamo!