Guidelines for implementing an aggregator
When you implement an aggregator by using the Active Site Analytics Mediator SPI, the following guidelines can be helpful.
- Implement the function that parses the DOM to collect and format all Active Site Analytics-specific data.
- Subscribe for the DOM notifications. Register the function that you implemented in the previous step with the object SiteAnalyticsMediator.
- Implement the logic that sends the collected data to the external analytics service.
- Implement the function that parses the DOM to collect and format
all Active Site Analytics-specific data.
- The implementation for collecting the data greatly depends on the themes, skins, and all the other components that might produce analytics-specific microformats. So, there is a dependency between the theme and its skins on the one hand and the aggregator.
- The aggregator implementation can affect the performance, as it increases the page rendering time in the browser. To mitigate this time increase, take care that the DOM processing required to collect the data is implemented efficiently. To achieve a good performance, you can use implementation details of your themes and skins. For example, you can use HTML identifiers in the theme markup to isolate the nodes that contain the Active Site Analytics-specific data into a DOM subtree that your aggregator can access efficiently. In any case, avoid traversing the entire DOM.
- Subscribe for the DOM notifications. Register the function that
you implemented in the previous step with the object SiteAnalyticsMediator.
- It is only during this registration step that you directly invoke the Active Site Analytics Mediator SPI. Register your function with the SiteAnalyticsMediator before the browser sends the onload event.
- Implement the logic that sends the collected data to the external
analytics service.
- To have your data analyzed, you send them to an external analytics service. This step is separated from step 1, as the aggregator cannot make assumptions as to how often it is notified about DOM changes. In a Web 2.0 portal environment with many Ajax components, multiple notifications per portal page or even per portlet interaction can occur. Therefore, this step requires a deep understanding of the analytics service. Even the contract with your analytics service provider can influence when and how frequently you want to send the collected data to the analytics service.
- If it does not matter how frequently data is transmitted to the analytics service, you can combine steps 1 and 3. For example, you can send the data directly to the analytics service after or even during the DOM parsing process. If the transmission frequency is relevant, store the data in a buffer, for example a JSON object or a cookie, during the DOM parsing process in step 1. To trigger sending the buffer contents to the analytics service, you can either use an external event or a specific data change. The trigger can be based on a time interval, for example a JavaScript timeout. You can also use the beforeunload event that the browser fires whenever the entire browser page is refreshed, or when a browser window or browser tab is closed.
- You have several options for how to send the collected data to the external analytics service. A widely spread method is to use a so-called tracking image. In this case, the aggregator adds an HTML image element to the DOM, which is hidden via CSS. The image source URL that points to the external analytics service is used to transport the collected data. After adding the image element to the DOM, the browser initiates an HTTP GET request to load the tracking image. As an alternative, you can also use an asynchronous XmlHttpRequest (XHR) to send the data to the external analytics service. This method is useful if you want to use HTTP POST requests to submit a large amount of data.
- Register your handler before the page finishes loading, that is, before the browser sends the onload event.
- Do not make assumptions about the frequency by which your aggregator gets notified about DOM changes. For a single page, multiple notifications can occur.
- Use separate steps for collecting and formatting the data, and for submitting the data to the external analytics server.
- The processing that is done by your aggregator affects the page rendering time in the browser.
- To ensure a better performance, use theme and skin implementation details. For example, use HTML identifiers for efficient DOM node lookups if available. Avoid traversing the entire DOM.
- Carefully decide when and how often you want to send the collected data to the analytics service. This decision might depend on your analytics service provider.
- Use an asynchronous way to send the collected data to the analytics service, for example a tracking image or an asynchronous XHR.
- You can use a JavaScript framework to implement your aggregator.