Open navigation

Multiple Orders Received From The Same IP Address

For sites using Magento Klevu module versions 3.x or 2.x, please refer to this article. For version 4.x, kindly follow this link.

When a customer places an order on your website, their IP address is recorded by Magento, which is used by the Klevu order synchronization process to associate customer actions with checkouts and provide conversion information in your KMC account.

If you are using a proxy or Web Application Firewall between your visitors and the web server, you may find that Magento records multiple IPs for the same order. You can see this happening if you look at the Placed from IP value on an order in the backend.

When sending orders to Klevu, we use the remote_ip value for the order, which is the value outside parentheses (in the example above, 192.168.240.2).

From version 2.5.3 of our extension, if a high number of orders in your database contain the same value for this field then you may see a warning message in your Magento admin panel.

Klevu has detected many checkout orders originating from the same IP address causing inaccuracies in Klevu sales analytics.

Why Is This A Problem?

This is often an indicator that the IP address of customer actions analytics (for example, searches and click events) will differ from the IP address for the conversion. When this happens, we cannot record that order as being Klevu driven, and the conversion rate for Klevu-led sales in the Merchant Centre will be inaccurate.

How Can I Resolve This?

1. First check that this is not a false positive report.
Some websites, such as B2B sites or those with a small number of returning customers, will naturally see the same IP address recorded multiple times.

2. Consult with your developers / server administrators to see if the server or firewall configuration is correct.
You may find that they are able to make configuration changes to set the correct IP address in the remote_ip field in your database. As there are many different services which may interfere with this value (Varnish, Proxy servers, firewalls), your server administrators will be best placed to determine whether this is a practicable solution.

3. If you cannot change the used IP value, your developers can extend the Klevu sync functionality to use one of the alternative IPs

Note: this guide utilises functionality available in the 2.5.3 version of the klevu/module-productsearch module.
If you are running an older version of the extension, you should upgrade before implementing any customisations.

With code level changes in your Magento installation, you can implement your own logic to set the IP address before the order record is sent to Klevu. To do so, first create a small custom Magento module, extending the Klevu_Search extension. For demonstration purposes, we have created this in Acme\MyModule

app/code/Acme/MyModule/registration.php

<?php

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register(
    ComponentRegistrar::MODULE,
    'Acme_MyModule',
    __DIR__
);

app/code/Acme/MyModule/etc/module.xml

<?xml version=“1.0”?>
<config xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=“urn:magento:framework:Module/etc/module.xsd”>
    <module name=“Acme_MyModule” setup_version=“1.0.0”>
        <sequence>
            <module name=“Klevu_Search”/>
        </sequence>
    </module>
</config>
 

Then, create an event observer containing your custom logic and attach it to the
acme_mymodule_klevu_search_order_sync_data_update event

app/code/Acme/MyModule/etc/events.xml

<?xml version=“1.0”?>
<config xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”
xsi:noNamespaceSchemaLocation=“urn:magento:framework:Event/etc/events.xsd”>
    <event name=“klevu_search_order_sync_send_before”>
        <observer name=“acme_mymodule_klevu_search_order_sync_data_update”
instance=“Acme\MyModule\Observer\Klevu\Search\Model\Order\Sync\SendBeforeObserver”/>
    </event>
</config>

app/code/Acme/MyModule/Observer/Klevu/Search/Model/Order/Sync/SendBeforeObserver.php


<?php

namespace Acme\MyModule\Observer\Klevu\Search\Model\Order\Sync;


use Magento\Framework\Event\Observer;

use Magento\Framework\Event\ObserverInterface; use Magento\Framework\Exception\NoSuchEntityException; use Magento\Sales\Api\Data\OrderItemInterface; use Magento\Sales\Api\OrderRepositoryInterface; class SendBeforeObserver implements ObserverInterface

{

/**

     * @var OrderRepositoryInterface

     */

    private $orderRepository;


    /**

     * @param OrderRepositoryInterface $orderRepository

     */

public function __construct( OrderRepositoryInterface $orderRepository ) { $this->orderRepository = $orderRepository; }

    /**

* @param Observer $observer * @return void */ public function execute(Observer $observer) { $eventData = $observer->getDataUsingMethod('event_data'); $orderItem = $eventData->getDataUsingMethod('order_item');

        if (!($orderItem instanceof OrderItemInterface) || !$orderItem->getOrderId()) {

            return;

        }

        try {

$order = $this->orderRepository->get($orderItem->getOrderId());

        } catch (NoSuchEntityException $e) {

            return;

}

        $xForwardedFor = trim((string)$order->getXForwardedFor());

        if (!$xForwardedFor) {

return; } $parameters = $eventData->getDataUsingMethod('parameters');

        $parameters['klevu_shopperIP'] = trim(current(explode(',', $xForwardedFor)));

$eventData->setData('parameters', $parameters); } }

In the above observer, we retrieve the order from the order_item object available in the event data. From the order, we take the x_forwarded_for value and return the first IP found (if there are multiple recorded).
This information is then updated in the event data, which is sent to Klevu.

Once you have created your module, you will need to enable it and recompile Magento

php bin/magento module:enable Acme_MyModule

php bin/magento setup:upgrade

php bin/magento setup:di:compile

php bin/magento setup:static-content:deploy

php bin/magento cache:clear

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.