Download the PHP package blomstra/fathom-analytics without Composer
On this page you can find all versions of the php package blomstra/fathom-analytics. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package fathom-analytics
Fathom Analytics
A Flarum extension. Integrate Fathom Analytics into your Flarum forum.
You can add custom events through your own extension! For more info, read the extending section
Installation
Install with composer:
Updating
Links
Extending
This extension is designed to be built upon by other Flarum extensions. We've tried to make this as simple as possible for you to do.
Creating an event
All custom events should be defined in your extension's common
folder. Create a new folder inside js/src/common
named fathomEvents
. This is where all your custom events will be stored.
Create a new Javascript/Typescript file in this folder with the following template:
Fill in the metadata accurately. It's strongly recommended that your id
is scoped to your extension to prevent conflicts.
You can import any Flarum code into this file, and run it inside the code(e) { }
method. To track an event occurring, call e.track()
and the extension will handle the rest.
:warning: Due to how the Fathom extension is designed, you will often need to import files from the
forum
namespace from Flarum or other extensions. This is ok, even though this file is incommon
, provided you only use these imports inside thecode(e)
method.
For example, if you want to track when any button is clicked in Flarum, your event might look like this:
For more examples of events, check out the default events included with the extension: js/src/common/DefaultEvents
.
Registering your events
After you define your events, you need to register them with the extension.
To do this, create a new file at src/js/common/registerFathomEvents.js
.
In this file, export a function which registers your events with app.fathomEventsRepository
:
You should import and call this registerFathomEvents()
function in your src/admin/index.js
and src/forum/index.js
files.
If you have multiple custom events, you can chain calls to
registerEvent()
:
If you build your extension JS, you should see your custom event(s) inside the Fathom Analytics extension settings. Custom events are accompanied by a small plug-in icon to show that they are from another extension.
Typescript support
For Typescript typings support, copy the code below into a new file at js/src/@types/fathom.d.ts
. Typescript should automatically pick this up and remove those red squiggles under your code: