Skip to content

4Analytics hooks

You can modify or extend 4Analytics behavior programmatically by using one or more of the hooks listed below. Hooks let you modify internal PHP structures or results computed by 4Analytics to better accomodate your website specific requirements.

They are events that are triggered at various moments by 4Analytics, providing code you write with internal information and possibly letting you modify this information.

Hooks are not altered when 4Analytics is updated

All the customization you do using hooks will survive 4Analytics updates. The hooks definition themselves will not change or be removed, unless the corresponding feature is modified or removed from 4Analytics of course.

When using hooks with 4Analytics, the following apply:

  • we cannot provide any form of support to the customization you make. You are on your own and the below documentation is the extent of information we'll provide to you.
  • you'll need suitable programming knowledge and understanding of Joomla internals to be able to write your own hooks handler
  • you may have to study 4Analytics code to learn if what you want to do is possible and how to do it. Again, we won't help your there, at least as part of regular support.

Usage

If you added any hook handler, make sure to absolutely always mention that whenever you open a support ticket. Your custom hooks can alter the way 4Analytics works, and may have consequences. We need to be aware of the existence of your hooks at all times.

Types

There are 2 types of hooks: filters and actions. Both are events that are triggered at different moment and to which you can respond.

The difference between them is:

  • filters: you receive some data, and you can return modified data. 4Analytics will subsequently use your modified data
  • action: you receive some data, but you cannot modify it. Or rather, you can modify it but 4Analytics will not use the result anyway

How to

As hooks are basically events, you must register your custom handler with 4Analytics for any hook you want to use. 4Analytics will then call your handler when the hook is run.

The most convenient way to register your hooks handler and include your custom code is to use 4Analytics functions file. The function file is unique and lives at:

/libraries/weeblr/foranalytics_functions.php

Create the file if it does not exist yet. You can put all your custom code in that file, or just use it to interface with 4Analytics and include more PHP code from wherever you want.

The 4Analytics function file must always start with:

<?php
/**
 * 4Analytics hooks file
 *
 * You can use 2 variables to access 4Analytics content:
 *
 * $factory: access variables
 * $hooks: add handlers
 */

// no direct access
defined('WBLIB_EXEC') || die;

If this preamble is missing, just copy/paste it at the top of the file.

After that, you can add your hook handler and your custom code. Here is an example that disable programatically the configuration rule that 4Analytics was about to use on the current page:

$hooks->add(
    'foranalytics_analytics_snippets',
    function ($ruleData) {
        return [];
    }
);

The $hooks variable shown in the example is always available to you inside the functions files, 4Analytics creates it for you.

Inside the functions file, you are inside of Joomla, meaning you can use Joomla API as you would in other contexts. You can for instance use the Joomla Factory class to access the application object. Make sure to add the proper namespace use statements if you do so.

API

Summary

4Analytics currently offers 6 actions in 1 groups.
4Analytics currently offers 9 filters in 8 groups.

Actions

4Analytics currently offers 6 actions in 1 groups.

Group: Events

foranalytics_onAfterInitialise

Events action

Hook to run the registered onAfterInitialise handlers.

@since 1.0.0

in /plugins/system/foranalytics/foranalytics.php
@line 106

foranalytics_onAfterRender

Events action

Hook to run the registered onAfterRoute handlers.

@since 1.0.0

in /plugins/system/foranalytics/foranalytics.php
@line 239

foranalytics_onAfterRenderComplete

Events action

Hook to run the registered onAfterRoute handlers.

@since 1.0.0

in /plugins/system/foranalytics/foranalytics.php
@line 295

foranalytics_onAfterRespond

Events action

Hook to run the registered onAfterRespond handlers.
Warning: body may be gzipped at this time.

@since 1.0.0

in /plugins/system/foranalytics/foranalytics.php
@line 367

foranalytics_onAfterRoute

Events action

Hook to run the registered onAfterRoute handlers.

@since 1.0.0

in /plugins/system/foranalytics/foranalytics.php
@line 181

foranalytics_onBeforeRespond

Events action

Hook to run the registered onBeforeRespond handlers.
Warning: body may be gzipped at this time.

@since 1.0.0

in /plugins/system/foranalytics/foranalytics.php
@line 343

Filters

4Analytics currently offers 9 filters in 8 groups.

Group: Admin

foranalytics_extensions_list

Admin filter

Filter the list of extensions installed on the site, for user display in the admin.

@param array $components List of objects each describing an extension.

@return array

@since 1.0.0

in /plugins/system/foranalytics/vendor/weeblr/foranalytics/api/controller/extensions.php
@line 85

Group: Analytics

foranalytics_analytics_snippets

Analytics filter

Filter the raw data used when outputting analytics snippet, for each configured
provider on the current page.

@param array $data Raw data to be used in snippets, per provider.

@return array

@since 1.0.0

in /plugins/system/foranalytics/vendor/weeblr/foranalytics/model/injector/analytics.php
@line 94

Group: Content

foranalytics_current_request_category

Content filter

Filter the content category for current request belongs to.

@param object $category The category object as already established by wbLib.

@return object

@since 1.0.0

in /plugins/system/foranalytics/vendor/weeblr/foranalytics/model/rules.php
@line 793

Group: Cron

foranalytics_cron

Cron filter

Execute actions ran over cron. Each job can update the request response to reflect
success or otherwise.

@param int $source The source of the cron request, either 'cron' or 'soft_cron'.

@return void

@since 1.0.0

in /plugins/system/foranalytics/vendor/weeblr/foranalytics/api/controller/cron.php
@line 103

Group: Customfields

foranalytics_cf_get_value_by_id

Customfields filter

Filter the value of a custom field for the current page request.

@param mixed $customFieldValue @param int $customFieldId Id of custom field in platform table @param string $fieldContext The context of the content being passed to the plugin. @param array $contentData The main page content array, to which the custom fields has been attached.

@return mixed

@since 2.1.1

in /plugins/system/foranalytics/vendor/weeblr/foranalytics/helper/customfields.php
@line 196

Group: Events

foranalytics_onPrivacyCollectAdminCapabilities

Events filter

Hook to run the registered onAfterInitialise handlers.

@since 1.0.0

in /plugins/system/foranalytics/foranalytics.php
@line 128

Group: Measurement

foranalytics_item_definition

Measurement filter

Filter the current item definition before returning it to the client.

@param array $itemDefinition Array of item_scope, item_type, item_lang, item_parent and item_id @param \Joomla\Input\Input $input

@return array

@since 1.0.0

in /plugins/system/foranalytics/vendor/weeblr/foranalytics/model/injector/analytics.php
@line 305

Group: Output

foranalytics_onAfterRenderComplete_body

Output filter

Filter the body of the CMS response at onAfterRender.

@param string $body Body of the current request.

@since 1.0.0

in /plugins/system/foranalytics/foranalytics.php
@line 308

foranalytics_onAfterRender_body

Output filter

Filter the body of the CMS response at onAfterRender.

@param string $body Body of the current request.

@since 1.0.0

in /plugins/system/foranalytics/foranalytics.php
@line 252