This PHP Module allows you to embed AFS Analytics dashboard in your admin with just a few lines of code.
composer require afsanalytics/dashboard
PHP >= 7.0
Please note that the page displaying AFS Analytics dashboard should not be public -- unless you want your stats to be public.
Including the dashboard on a page is done by creating a container element, and then calling the render method.
print '<div id=my_custom_id></div>';
$db = new \AFSAnalytics\Dashboard\Controller( YOUR_API_KEY );
$db->setParentSelector('#my_custom_id')
->render()
;
In addition to inserting the code displaying the dashboard, you need to run the ajax server responsible for calling AFS Analytics REST API.
This can be done with just two lines of codes:
$db = new \AFSAnalytics\Dashboard\Controller( YOUR_API_KEY );
$db->runAJAXServer();
This code can be inserted on the same page, or on a separate one. In either case it must be placed before any outpout.
In order to secure access to the Ajax Server, you might want to add some custom data to all Ajax calls.
You can do this via javascript:
AFSA.hook.prepareAjaxData = function (data) {
data.my_property = my_value;
};
You can create an API Key at https://dev.afsanalytics.com
Please note that a valid AFS Analytics account will be required, as a subscription including API Access.
Embed the dashboard inside the specified selector.
Return the dashboard HTML code.
$db ->setParentSelector('#my_custom_id')
->render([
'css' => string // custom css to be inserted - optional
])
Disable all eCommerce related reports.
Set dashboard langage.
Currently supported $lng values : 'en', 'fr'
See the project changelog
Contributions are always welcome.
Please email dev@afsanalytics.com
.
This package is released under the MIT License. See the bundled LICENSE file for details.