| | |
| | | <?php |
| | | namespace JVBase\integrations; |
| | | |
| | | use JVBase\managers\CacheManager; |
| | | use JVBase\managers\Cache; |
| | | use WP_Error; |
| | | use WP_Post; |
| | | use Exception; |
| | |
| | | private string $events_table; |
| | | private string $metrics_table; |
| | | |
| | | public function __construct(?int $userID = null) |
| | | protected static array $instances = []; |
| | | public static function getInstance(?int $userID = null):self |
| | | { |
| | | $key = is_null($userID) ? 'base' : $userID; |
| | | if (!array_key_exists($key, self::$instances)) { |
| | | self::$instances[$key] = new static($userID); |
| | | } |
| | | return self::$instances[$key]; |
| | | } |
| | | |
| | | protected function __construct(?int $userID = null) |
| | | { |
| | | $this->service_name = 'umami'; |
| | | $this->title = 'Umami.js'; |
| | |
| | | */ |
| | | public function renderTrackingScript(): void |
| | | { |
| | | // Skip on local environments |
| | | if (JVB_TESTING) { |
| | | return; |
| | | } |
| | | if (!$this->isSetUp() || is_admin()) { |
| | | return; |
| | | } |
| | | |
| | | // Skip on local environments |
| | | if (strpos(get_home_url(), JVB_LOCAL) !== false) { |
| | | return; |
| | | } |
| | | |
| | | $script_url = $this->getTrackingScriptUrl(); |
| | | $website_id = $this->getWebsiteId(); |
| | |
| | | if ($data) { |
| | | // Clear cache for today |
| | | $cache_key = md5("analytics_{$today}_{$today}"); |
| | | $this->cache->delete($cache_key); |
| | | $this->cache->forget($cache_key); |
| | | |
| | | return [ |
| | | 'success' => true, |