2

So,

In this doc:

Online Customers

It is explained how Magento 2 checks if customers are online and how to set the interval to check this.

BUT

What is not so clear, is how Magento 2 does this. Look at the following sentence:

The interval of time that customers are shown as currently online is set in the configuration, and determines how long the customer’s activity is visible from the Admin

Let's say the interval is 15 minutes. Does this mean Magento 2:

  • Checks ALL customers every 15 minutes AT ONCE which customers are online and compares them with the previous record of people who were online?

Or does Magento 2:

  • Checks every customer individually every 15 minutes (starting from their visiting time) to check wether they are still active on the website or not? So this would mean that Magento has to check A LOT when there are a lot of people are active on the webshop.

And my final question:

  • Does Magento 2 sees a customer as 'Online' when they have the paged opened in a tab, but are not currently active in that said tab? So they are active in another tab or are just doing something else on their devices?

1 Answer 1

2

Check Magento customer module logic in :/vendor/magento/module-customer/Model/ResourceModel/Online/Grid/Collection.php

/**
     * Init collection select
     *
     * @return $this
     */
    protected function _initSelect()
    {
        parent::_initSelect();
        $connection = $this->getConnection();
        $lastDate = $this->date->gmtTimestamp() - $this->visitorModel->getOnlineInterval() * self::SECONDS_IN_MINUTE;
        $this->getSelect()->joinLeft(
            ['customer' => $this->getTable('customer_entity')],
            'customer.entity_id = main_table.customer_id',
            ['email', 'firstname', 'lastname']
        )->where(
            'main_table.last_visit_at >= ?',
            $connection->formatDate($lastDate)
        );
        $expression = $connection->getCheckSql(
            'main_table.customer_id IS NOT NULL AND main_table.customer_id != 0',
            $connection->quote(Visitor::VISITOR_TYPE_CUSTOMER),
            $connection->quote(Visitor::VISITOR_TYPE_VISITOR)
        );
        $this->getSelect()->columns(['visitor_type' => $expression]);
        return $this;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.