Skip to content

Commit 673d45a

Browse files
authored
Merge pull request #3 from mauricerenck/develop
Beta update
2 parents 2016372 + 2ae6d32 commit 673d45a

16 files changed

+2397
-27
lines changed

README.md

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ For first screens of the panel have a look here: https://maurice-renck.de/de/pro
2222
* ✅ Snippet for the advanced Podlove Player
2323
* ✅ Configure and style your website player within the panel
2424
* ✅ Routing for downloads/tracking
25+
* ✅ Tracking of downloads using Kirby and the episoden markdown
26+
* ✅ Tracking of downloads using Kirby and MySQL
27+
* ✅ Tracking of episodes/feeds using Matomo
2528
* Snippet for Podlove Subscribe box
26-
* Tracking of downloads using Matomo
27-
* Tracking of downloads using Kirby and the episoden markdown
28-
* Tracking of downloads using Kirby and MySQL
2929

3030

3131
## Installation
@@ -38,6 +38,54 @@ For first screens of the panel have a look here: https://maurice-renck.de/de/pro
3838

3939
If you want to use the PodLove-Player and style it, you can try around here: https://docs.podlove.org/podlove-web-player/theme.html
4040

41+
## Configuration
42+
43+
### Internal Tracking
44+
You can use the built in tracking by setting the following in your `config.php`
45+
`'mauricerenck.podcaster.statsInternal' => true`
46+
47+
#### Episode
48+
To track your episodes a special route has to be triggered. Kirby Podcaster does this by default. If you want, you can change this route by setting:
49+
50+
`mauricerenck.podcaster.downloadTriggerPath`
51+
52+
Default is `download`
53+
54+
#### Feed
55+
If you want to track your rss-feed, you have to set the slug of your feed in the config.php. If your feed url is `https://podcast.tld/myfeed/` set:
56+
57+
```
58+
'mauricerenck.podcaster.defaultFeed' => 'myfeed',
59+
```
60+
61+
Default value is `feed`, so if you name your rss-feed-page `feed` everything is find and you don't have to do anything.
62+
63+
#### Tracking Mode
64+
You can either use the file method, then your downloads will be directly stored in your episode markdown file. Note that this *can* lead to problems if there are a lot of simulatiously downoads. You may run better by using the mysql method.
65+
66+
Or you can use MySQL:
67+
```
68+
'mauricerenck.podcaster.statsType' => 'mysql',
69+
'mauricerenck.podcaster.statsHost' => 'HOSTNAME',
70+
'mauricerenck.podcaster.statsDatabase' => 'DATABASE',
71+
'mauricerenck.podcaster.statsUser' => 'USER',
72+
'mauricerenck.podcaster.statsPassword' => 'PASSWORD'
73+
```
74+
Before using the MySQL statistics please make sure to create the tables within your database. You can find the SQL import in the `res` directory of this repository called `podcasterStats.sql`
75+
76+
**NOTE**
77+
Downloads can currenly be tracked, but there are no visual stats in the panel, yet.
78+
79+
### Matomo
80+
You can enalbe download tracking via Matomo per feed. Go to your feed settings and click on the Tracking tab. Fill in all needed values.
81+
82+
To make sure Kirby Podcaster can access your Matomo API, you must set these to values in your config.php
83+
84+
```
85+
'mauricerenck.podcaster.matomoToken' => 'my-secret-token',
86+
'mauricerenck.podcaster.matomoBaseUrl' => 'https://my-matomo-url.tld/'
87+
```
88+
4189
## Add Player to template
4290

4391
If you want an audio player appear on your episode page, just add the follow snippet to your template: `<?php snippet('podcaster-player'); ?>`

blueprints/pages/podcasterfeed.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,102 @@ tabs:
251251
text:
252252
- Invisible
253253
- Visible
254+
width: 1/4
255+
tracking:
256+
label: Tracking
257+
columns:
258+
- width: 1/3
259+
sections:
260+
matomo:
261+
type: fields
262+
fields:
263+
headlineMatomo:
264+
type: headline
265+
label: Matomo settings
266+
infoMatomo:
267+
type: info
268+
theme: info
269+
label: Attention
270+
text: Make sure to set the token and base-url in your config.php
271+
- width: 1/3
272+
sections:
273+
matomoEpisode:
274+
type: fields
275+
fields:
276+
headlineMatomoEpisode:
277+
type: headline
278+
label: Matomo Episode Settings
279+
podcasterMatomoEnabled:
280+
label: Enable Matomo episode tracking
281+
help: Tracking will only be enabled for this podcast if you run another one, enable it there, too
282+
type: toggle
283+
default: no
284+
text:
285+
- disabled
286+
- enabled
287+
width: 1/4
288+
podcasterMatomoSiteId:
289+
label: Site Id
290+
help: Your Matomo Site Id.
291+
type: text
292+
width: 1/4
293+
podcasterMatomoGoalId:
294+
label: Goal Id
295+
help: If you want to track a certain goal, fill in its Id. Leave empty to disable.
296+
type: text
297+
width: 1/4
298+
podcasterMatomoEventName:
299+
label: Event name
300+
help: If you want to track a certain event, fill in its name here. Leave empty to disable.
301+
type: text
302+
width: 1/4
303+
podcasterMatomoAction:
304+
label: Action
305+
help: If you want to track the download action, enable this.
306+
type: toggle
307+
default: no
308+
text:
309+
- disabled
310+
- enabled
311+
width: 1/4
312+
- width: 1/3
313+
sections:
314+
matomoFeed:
315+
type: fields
316+
fields:
317+
headlineMatomoFeed:
318+
type: headline
319+
label: Matomo Feed Settings
320+
podcasterMatomoFeedEnabled:
321+
label: Enable Matomo rss-feed tracking
322+
help: Tracking will only be enabled for this podcast if you run another one, enable it there, too
323+
type: toggle
324+
default: no
325+
text:
326+
- disabled
327+
- enabled
328+
width: 1/4
329+
podcasterMatomoFeedSiteId:
330+
label: Site Id
331+
help: Your Matomo Site Id.
332+
type: text
333+
width: 1/4
334+
podcasterMatomoFeedGoalId:
335+
label: Goal Id
336+
help: If you want to track a certain goal, fill in its Id. Leave empty to disable.
337+
type: text
338+
width: 1/4
339+
podcasterMatomoFeedEventName:
340+
label: Event name
341+
help: If you want to track a certain event, fill in its name here. Leave empty to disable.
342+
type: text
343+
width: 1/4
344+
podcasterMatomoFeedAction:
345+
label: Action
346+
help: If you want to track the download action, enable this.
347+
type: toggle
348+
default: no
349+
text:
350+
- disabled
351+
- enabled
254352
width: 1/4

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
"files": [
1515
"config.php",
1616
"utils/PodcasterUtils.php",
17-
"utils/PodcasterAudioUtils.php"
17+
"utils/PodcasterAudioUtils.php",
18+
"utils/PodcasterStats.php",
19+
"utils/PodcasterStatsFile.php",
20+
"utils/PodcasterStatsMysql.php",
21+
"lib/PiwikTracker.php"
1822
]
1923
},
2024
"require": {

config.php

Lines changed: 88 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
<?php
2-
namespace Plugin\Podcast;
2+
namespace Plugin\Podcaster;
33
use Kirby;
44
use Kirby\Exception\Exception;
5+
use \PiwikTracker;
56

67
Kirby::plugin('mauricerenck/podcaster', [
78
'options' => [
8-
'downloadTriggerPath' => 'download'
9-
// 'widgetEntries' => 10,
10-
// 'piwikBase' => null,
11-
// 'piwikId' => null,
12-
// 'piwikToken' => '',
13-
// 'piwikGoalId' => null,
14-
// 'piwikEventName' => 'Download',
15-
// 'piwikAction' => false,
16-
// 'GAUA' => false,
17-
// 'GA.pageView' => false,
18-
// 'GA.eventName' => 'Download',
9+
'statsInternal' => false,
10+
'statsType' => 'mysql',
11+
'statsHost' => null,
12+
'statsDatabase' => null,
13+
'statsUser' => null,
14+
'statsPassword' => null,
15+
'matomoToken' => null,
16+
'matomoBaseUrl' => null
1917
],
2018
'templates' => [
2119
'podcasterfeed' => __DIR__ . '/templates/podcasterfeed.php'
@@ -29,7 +27,84 @@
2927
'podcaster-podlove-player' => __DIR__ . '/snippets/podlove-player.php',
3028
'podcaster-html5-player' => __DIR__ . '/snippets/html5-player.php'
3129
],
32-
'routes' => require_once __DIR__ . '/routes.php',
30+
'routes' => [
31+
[
32+
'pattern' => '(:all)/' . option('mauricerenck.podcaster.defaultFeed', 'feed'),
33+
'action' => function ($slug) {
34+
$page = page($slug . '/' . option('mauricerenck.podcaster.defaultFeed', 'feed'));
35+
36+
if(option('mauricerenck.podcaster.statsInternal') === true) {
37+
$stats = new PodcasterStats();
38+
$trackingDate = time();
39+
$stats->increaseFeedVisits($page, $trackingDate);
40+
}
41+
42+
if($page->podcasterMatomoFeedEnabled()->isTrue()) {
43+
$matomo = new PiwikTracker($page->podcasterMatomoFeedSiteId(), option('mauricerenck.podcaster.matomoBaseUrl'));
44+
45+
$matomo->setTokenAuth(option('mauricerenck.podcaster.matomoToken'));
46+
$matomo->disableSendImageResponse();
47+
$matomo->disableCookieSupport();
48+
$matomo->setUrl($page->url());
49+
$matomo->setIp($_SERVER['REMOTE_ADDR']);
50+
51+
if($page->podcasterMatomoFeedGoalId()->isNotEmpty()) {
52+
$matomo->doTrackGoal($page->podcasterMatomoFeedGoalId(), 1);
53+
}
54+
55+
if($page->podcasterMatomoFeedEventName()->isNotEmpty()) {
56+
$matomo->doTrackEvent($page->podcasterTitle(), $page->podcasterMatomoFeedEventName(), 1);
57+
}
58+
59+
if($page->podcasterMatomoFeedAction()->isTrue()) {
60+
$matomo->doTrackAction($page->url(), 'download');
61+
}
62+
}
63+
64+
return($page);
65+
}
66+
],
67+
[
68+
'pattern' => '(:all)/' . option('mauricerenck.podcaster.downloadTriggerPath', 'download') . '/(:any)',
69+
'action' => function ($slug, $filename) {
70+
$episode = page($slug);
71+
$podcast = $episode->siblings()->find('feed');
72+
73+
if(option('mauricerenck.podcaster.statsInternal') === true) {
74+
$stats = new PodcasterStats();
75+
$trackingDate = time();
76+
$stats->increaseDownloads($episode, $trackingDate);
77+
}
78+
79+
if($podcast->podcasterMatomoEnabled()->isTrue()) {
80+
$matomo = new PiwikTracker($podcast->podcasterMatomoSiteId(), option('mauricerenck.podcaster.matomoBaseUrl'));
81+
82+
// setup
83+
$matomo->setTokenAuth(option('mauricerenck.podcaster.matomoToken'));
84+
$matomo->disableSendImageResponse();
85+
$matomo->disableCookieSupport();
86+
$matomo->setUrl($episode->url());
87+
$matomo->setIp($_SERVER['REMOTE_ADDR']);
88+
89+
if($podcast->podcasterMatomoGoalId()->isNotEmpty()) {
90+
$matomo->doTrackGoal($podcast->podcasterMatomoGoalId(), 1);
91+
}
92+
93+
if($podcast->podcasterMatomoEventName()->isNotEmpty()) {
94+
$matomo->doTrackEvent($podcast->podcasterTitle(), $episode->title(), $podcast->podcasterMatomoEventName());
95+
}
96+
97+
if($podcast->podcasterMatomoAction()->isTrue()) {
98+
$matomo->doTrackAction($episode->url(), 'download');
99+
}
100+
}
101+
102+
$filename = str_replace('.mp3', '', $filename);
103+
return $episode->audio($episode->podcasterMp3())->first();
104+
return $file;
105+
}
106+
]
107+
],
33108
'hooks' => [
34109
'file.create:after' => function ($file) {
35110
if($file->isAudio()) {

0 commit comments

Comments
 (0)