mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-13 03:27:45 +02:00
feat: update analytics so to meet IABv2 requirements
- https://iabtechlab.com/wp-content/uploads/2017/12/Podcast_Measurement_v2-Dec-20-2017.pdf - no IP address is ever stored on the server. Only aggregate data is stored in the dababase. - rolling 24-hour window - castopod does not do pre-load - IP Blacklisting https://github.com/client9/ipcat - user-agent Filtering https://github.com/opawg/user-agents - ignores 2 bytes range "Range: 0-1" (performed by official Apple iOS Podcast app) - in case of partial content, adds up all requests to check >1mn was downloaded - identifying Uniques is done with a combination of IP Address and User Agent - add AMcharts - add some graphs - add regions to analytics - add ipcat blacklist - enhance useragents performances - add filesize and header size in order to calculate 1mn downloads - update publisher ID3 field - update castopod icon - add disclaimer and warning import form translation - update docs/setup-development.md closes #10
This commit is contained in:
parent
5417be0049
commit
03e23a28bf
61 changed files with 3162 additions and 540 deletions
113
app/Models/AnalyticsPodcastsByEpisodeModel.php
Normal file
113
app/Models/AnalyticsPodcastsByEpisodeModel.php
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Class AnalyticsPodcastsByEpisodeModel
|
||||
* Model for analytics_podcasts_by_episodes table in database
|
||||
* @copyright 2020 Podlibre
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
||||
* @link https://castopod.org/
|
||||
*/
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use CodeIgniter\Model;
|
||||
|
||||
class AnalyticsPodcastsByEpisodeModel extends Model
|
||||
{
|
||||
protected $table = 'analytics_podcasts_by_episode';
|
||||
|
||||
protected $allowedFields = [];
|
||||
|
||||
protected $returnType = \App\Entities\AnalyticsPodcastsByEpisode::class;
|
||||
protected $useSoftDeletes = false;
|
||||
|
||||
protected $useTimestamps = false;
|
||||
|
||||
/**
|
||||
* @param int $podcastId, $episodeId
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDataByDay(int $podcastId, int $episodeId = null): array
|
||||
{
|
||||
if (!$episodeId) {
|
||||
if (
|
||||
!($found = cache(
|
||||
"{$podcastId}_analytics_podcast_by_episode_by_day"
|
||||
))
|
||||
) {
|
||||
$lastEpisodes = (new EpisodeModel())
|
||||
->select('id, season_number, number, title')
|
||||
->orderBy('id', 'DESC')
|
||||
->where(['podcast_id' => $podcastId])
|
||||
->findAll(5);
|
||||
|
||||
$found = $this->select('age AS X');
|
||||
|
||||
$letter = 97;
|
||||
foreach ($lastEpisodes as $episode) {
|
||||
$found = $found
|
||||
->selectSum(
|
||||
'(CASE WHEN `episode_id`=' .
|
||||
$episode->id .
|
||||
' THEN `hits` END)',
|
||||
chr($letter) . 'Y'
|
||||
)
|
||||
->select(
|
||||
'"' .
|
||||
(empty($episode->season_number)
|
||||
? ''
|
||||
: $episode->season_number) .
|
||||
(empty($episode->number)
|
||||
? ''
|
||||
: '-' . $episode->number . '/ ') .
|
||||
$episode->title .
|
||||
'" AS ' .
|
||||
chr($letter) .
|
||||
'Value'
|
||||
);
|
||||
$letter++;
|
||||
}
|
||||
|
||||
$found = $found
|
||||
->where([
|
||||
'podcast_id' => $podcastId,
|
||||
'age <' => 60,
|
||||
])
|
||||
->groupBy('X')
|
||||
->orderBy('X', 'ASC')
|
||||
->findAll();
|
||||
|
||||
cache()->save(
|
||||
"{$podcastId}_analytics_podcast_by_episode_by_day",
|
||||
$found,
|
||||
14400
|
||||
);
|
||||
}
|
||||
return $found;
|
||||
} else {
|
||||
if (
|
||||
!($found = cache(
|
||||
"{$podcastId}_{$episodeId}_analytics_podcast_by_episode_by_day"
|
||||
))
|
||||
) {
|
||||
$found = $this->select('date as labels')
|
||||
->selectSum('hits', 'values')
|
||||
->where([
|
||||
'episode_id' => $episodeId,
|
||||
'podcast_id' => $podcastId,
|
||||
])
|
||||
->groupBy('labels')
|
||||
->orderBy('labels', 'ASC')
|
||||
->findAll();
|
||||
|
||||
cache()->save(
|
||||
"{$podcastId}_{$episodeId}_analytics_podcast_by_episode_by_day",
|
||||
$found,
|
||||
14400
|
||||
);
|
||||
}
|
||||
return $found;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue