Magento is caching 'catalog_controller_product_view' event

controller_action_predispatch is cached when FPC is on. So you cannot rely on it.

You need to catch controller_front_send_response_before. It is fired even when FPC is on.

You /etc/frontend/events.xml should look like:

<?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="controller_front_send_response_before">
        <observer name="ws_ag_controller_front_send_response_before" instance="Namespace\Module\Observer\ResponseBefore" />
    </event>
</config>

catalog_controller_product_view event cannot be used in conjunction with FPC cache since Magento will not raise it after the first visit.

Option 1 - The AJAX way:

You have to:

  • Create a controller accepting your product's id
  • Add a JS block to your product's page calling your controller and passing the product's id
  • Insert your tracking code in your new controller

Option 2 - Predispatch event (not tested):

Otherwise you could try using controller_action_predispatch event that should be called even with FPC enabled.

You will have to get the product's information by your own in this case.