1

For example there are the rows at report_viewed_product_index:

index_id    visitor_id  customer_id product_id  store_id    added_at
19          NULL          20116     10642       2       2016-03-04 
45          NULL          20162     6246        1       2016-03-05
108         NULL          15229     20157       1       2016-03-14
190         378345      NULL        21092       2       2016-03-30
191         381787      NULL        20184       1       2016-03-30

As I understand customer_id IS NULL means that we have 'not logged customer' or visitor. What does visitor_id is NULL mean?

1 Answer 1

0

IIRC:

  • visitor_id is NULL when it is a customer, thus customer_id is not NULL.
  • customer_id is NULL when it is not a logged in customer, thus visitor_id is not NULL.

The case where both are NULL is not an easy one.

The vistor_id is retrieved from the Mage_Log_Model_Visitor class.

The only possibility that comes to my mind is that it is a visitor that has an excluded user agent, which means that is a bot (like Google Bot).

As you can see from the constructor, the request logging is skipped in that case:

protected function _construct()
{
    $this->_init('log/visitor');
    $userAgent = $this->_httpHelper->getHttpUserAgent();
    $ignoreAgents = $this->_config->getNode('global/ignore_user_agents');
    if ($ignoreAgents) {
        $ignoreAgents = $ignoreAgents->asArray();
        if (in_array($userAgent, $ignoreAgents)) {
            $this->_skipRequestLogging = true;
        }
    }
    if ($this->_logCondition->isLogDisabled()) {
        $this->_skipRequestLogging = true;
    }
}

The ignored user agents are defined under app/code/core/Mage/Log/etc/config.xml and are the following:

Finally, the case where both are not NULL

From what I understood, it happens in the following case:

  • logged out customer visits a product page
  • leaves the website
  • comes back and logs in as a customer
  • revisits the same product page

In that case, Magento will keep both values.

The visitor data is later set to NULL when the customer logs out with the following code:

public function purgeVisitorByCustomer(Mage_Reports_Model_Product_Index_Abstract $object)
{
    /**
     * Do nothing if customer not logged in
     */
    if (!$object->getCustomerId()) {
        return $this;
    }

    $bind   = array('visitor_id'      => null);
    $where  = array('customer_id = ?' => (int)$object->getCustomerId());
    $this->_getWriteAdapter()->update($this->getMainTable(), $bind, $where);

    return $this;
}
6
  • 1
    OK. Thanks. But I have cases when customer_id IS NOT NULL and visitor_id IS NOT NULL too. What does it mean? Commented May 24, 2016 at 8:09
  • @BorisRuvinsky good question I've updated my answer Commented May 24, 2016 at 8:23
  • Many thanks for the detailed answer. Glad to know that the bots also taken into account. But what about the case where both are NOT NULL Commented May 24, 2016 at 8:33
  • @BorisRuvinsky feel free to mark your question as answered so others will benefit from it ;) Commented May 24, 2016 at 8:34
  • @ Raphael at Digital Pianism Of course!!! Please explain me the last ** NOT NULL** case! Commented May 24, 2016 at 8:37

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.