Skip to content
This repository was archived by the owner on Mar 9, 2023. It is now read-only.

Tracking

tuegeb edited this page Mar 15, 2017 · 3 revisions

Clicks

The click events are done by JavaScript code. Therefore the script factfinder/tracking.js is included (by the layout/factfinder/tracking.xml) into the search result page only if tracking is enabled in the backend. (These conditions are handled by the method Flagbit_FactFinder_Model_Observer::addTrackingHandles, which is triggered by the event controller_action_layout_load_before (=> configured inside the config.xml). If the conditions match, this method will add the layout-handle factfinder_clicktracking_enabled into the page, which is defined inside the layout/factfinder/tracking.xml).

The inclusion of that script won't do anything by its own. The initialization of this script is done inside the templates factfinder/tracking/click.phtml and factfinder/tracking/recommendation.phtml (represented by the classes Flagbit_FactFinder_Block_Tracking_Click respectively Flagbit_FactFinder_Block_Tracking_Recommendation) which are also included by the layout handle described above. It will initialize the tracking script with this data:

  • The css-selector which should match on the html element that contains all products. (=> performance improvement)
  • The relevant tracking information for each product added as a JSON object (see the method getJsonDataObject()). The keys of these objects are the product IDs.
  • Mapping data for each product. The mapping is done from the product URL to the ID.
  • This mapping data is used by the tracking script to find all matching products URLs and attach a click event to it. Later when the click happens it looks up the relevant tracking information by the known ID and sends this data to the specified tracking URL:
  • URL where the tracking should be sent to.
  • Flag "asynchronous": set to false so the AJAX request should not be done asynchronous. This is necessary as the click request happens directly before the browser wants to go to the next page (because of the click). The most browsers will interrupt an asynchronous request and the event would never be tracked.

The tracking request will be handled by one of the methods at the Flagbit_FactFinder_ProxyController without much logic - just sent to the correct destination of FACT-Finder.

Cart and Checkout

At the etc/config.xml there is are "event handlers" defined for the events sales_order_place_after (=> cart) and checkout_cart_product_add_after (=> checkout). In both cases a method of the class Flagbit_FactFinder_Model_Observer is defined which handles the particular tracking event:

  • addToCartTracking: send the cart event for the currently added product directly to FACT-Finder (request is done immediately)
  • addOrderDetailsToQueue: the checkout events are not sent to FACT-Finder immediately but saved into a database table instead (=> table definition). This queue is handled by a scheduled job that must be triggered by Magento's Cronjob system. For each call the method processOrderQueue of the same Observer class is triggered, which will read all entries of the database table and send each event to FACT-Finder and delete it afterwards. The configuration of this cronjob is also inside the config.xml at the xml node .../crontab/jobs/factfinder_tracking_queue_processing.

Clone this wiki locally