Magento automatic gender recognition plugin

Today we’re going to create an extension for automatic gender recognition for customers. Extension is based on Rapleaf personalization API. Rapleaf provides demographic and lifestyle data (age, gender, marital status, income, etc.) on personal consumer email addresses (but not for business emails). They partner with dozens of large (and small) data companies to aggregate data and tie it to email addresses.
You can create a free Rapleaf account to get an API key for 1000 free age and gender queries.
Let’s get started…

1. Inchoo_Autogender.xml

Firstly we have to create the Inchoo_Autogender.xml file in /app/etc/modules folder.

<?xml version="1.0"?>

2. config.xml

Second step is to create the config.xml file in /app/code/local/Inchoo/Autogender/etc folder. The content is as follows:

<?xml version="1.0"?>

3. Observer.php

The final step is to create the Observer.php file in /app/code/local/Inchoo/Autogender/Model folder with the following content:

class Inchoo_Autogender_Model_Observer
    public function getGender($observer = null)
                $customer = $observer->getCustomer();
                $api_key = '... your api key ...';
                $client = new Zend_Http_Client();
                $client->setUri('' . $api_key .
                                '&email=' . urlencode($customer->getEmail()) .
                                '&first=' . urlencode($customer->getFirstname()) .
                                '&last=' . urlencode($customer->getLastname())
                $client->setConfig(array('maxredirects' => 0, 'timeout' => 2));
                $response = $client->request();
                if ($response->getStatus() < 200 || $response->getStatus() >= 300)
                        sprintf("Rapleaf query failed. (status: %s), (message: %s)",
                    $data = json_decode($response->getBody(), true);
                    if(array_key_exists('gender', $data))
            catch (Exception $e)
                    sprintf("Exception in Rapleaf query. (message: %s)",


Extension listens to the customer_register_success event that is dispatched when ever the new customer is registered (check the /app/code/core/Mage/Customer/controllers/AccountController.php file, createPostAction method).
Extension then hits the Rapleaf API server with customers data and if Rapleaf has any information about the customer, it sends that back.

  • Use the extension at your risk.
  • Check Rapleaf’s privacy policy.
  • Check var/log/rapleaf_api.log from time to time.

GitHub Repository

You made it all the way down here so you must have enjoyed this post! You may also like:

Custom API for Magento 2 Davor Simek
Davor Simek, | 25

Custom API for Magento 2

Magento 2 API usage with examples Tomas Novoselic
, | 43

Magento 2 API usage with examples

How to configure Magento REST and oAuth settings Darko Goles
Darko Goles, | 26

How to configure Magento REST and oAuth settings

1 comment

  1. Easy to install magento 2.0
    Hope it will be useful with somebody:

    Focused on seven key goals in building Magento 2:
    Update the technology stack
    Streamline the customization process
    Facilitate frontend development
    Reduce upgrade efforts and costs
    Improve performance and scalability
    Deliver better quality, testing resources, and documentation
    Increase engagement with the Magento community

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.