xref: /webtrees/app/Module/StatcounterModule.php (revision 37eb8894d5d4381f3fd9b791a53a32f0012b32ec)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 webtrees development team
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\Module;
19
20/**
21 * Class StatcounterModule - add support for statcounter.
22 */
23class StatcounterModule extends AbstractModule implements ModuleAnalyticsInterface
24{
25    use ModuleAnalyticsTrait;
26
27    /**
28     * How should this module be labelled on tabs, menus, etc.?
29     *
30     * @return string
31     */
32    public function title(): string
33    {
34        return 'Statcounter™';
35    }
36
37    /**
38     * Form fields to edit the parameters.
39     *
40     * @return string
41     */
42    public function analyticsFormFields(): string
43    {
44        return view('admin/analytics/statcounter-form', $this->analyticsParameters());
45    }
46
47    /**
48     * Home page for the service.
49     *
50     * @return string
51     */
52    public function analyticsHomePageUrl(): string
53    {
54        return 'https://statcounter.com';
55    }
56
57    /**
58     * The parameters that need to be embedded in the snippet.
59     *
60     * @return string[]
61     */
62    public function analyticsParameters(): array
63    {
64        return [
65            'STATCOUNTER_PROJECT_ID' => $this->getPreference('STATCOUNTER_PROJECT_ID'),
66            'STATCOUNTER_SECURITY_ID' => $this->getPreference('STATCOUNTER_SECURITY_ID'),
67        ];
68    }
69
70    /**
71     * Embed placeholders in the snippet.
72     *
73     * @param string[] $parameters
74     *
75     * @return string
76     */
77    public function analyticsSnippet(array $parameters): string
78    {
79        return view('admin/analytics/statcounter-snippet', $parameters);
80    }
81}
82