diff --git a/data/goURL.sql b/data/goURL.sql index 98b7a5b..75a77a1 100644 --- a/data/goURL.sql +++ b/data/goURL.sql @@ -27,6 +27,7 @@ CREATE TABLE IF NOT EXISTS `tblURLs` ( `submitDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `createdBy` varchar(25) DEFAULT NULL, `redirects` int(11) unsigned DEFAULT 0, + `qrCodeScans` int(11) unsigned DEFAULT 0, `lastRedirect` timestamp NULL, `maliciousCheck` enum('checked', 'unchecked', 'protected')NOT NULL DEFAULT 'unchecked', PRIMARY KEY (`urlID`) @@ -35,6 +36,7 @@ CREATE TABLE IF NOT EXISTS `tblURLs` ( -- ALTER TABLE `tblURLs` ADD COLUMN `groupID` int(10) unsigned NULL AFTER `urlID`; -- ALTER TABLE `tblURLs` ADD COLUMN `lastRedirect` timestamp NULL AFTER `redirects`; -- ALTER TABLE `tblURLs` ADD COLUMN `maliciousCheck` enum('checked', 'unchecked', 'protected') NOT NULL DEFAULT 'unchecked' AFTER `lastRedirect`; +-- ALTER TABLE `tblURLs` ADD COLUMN `qrCodeScans` int(11) unsigned DEFAULT 0 AFTER `redirects`; DROP TABLE IF EXISTS `tblGroups`; CREATE TABLE IF NOT EXISTS `tblGroups` ( diff --git a/src/goController.php b/src/goController.php index 0a0b1be..acaca3a 100644 --- a/src/goController.php +++ b/src/goController.php @@ -397,7 +397,7 @@ private function handleRouteURLQRCodePNG() $this->handle404(FALSE); } - $shortURL = $this->lilurl->getShortURL($this->goId); + $shortURL = $this->lilurl->getShortURL($this->goId) . '?qr'; $pngPrefix = __DIR__ . '/../data/qr/'; $qrCodeHash = hash("sha512", $shortURL); $qrCache = $pngPrefix . 'cache/' . $this->qrCachePrefix . hash("sha512", $shortURL) . '.png'; @@ -449,7 +449,7 @@ private function handleRouteURLQRCodeSVG() $this->handle404(false); } - $shortURL = $this->lilurl->getShortURL($this->goId); + $shortURL = $this->lilurl->getShortURL($this->goId) . '?qr'; $svgPrefix = __DIR__ . '/../data/qr/'; $qrCodeHash = hash("sha512", $shortURL); $qrCache = $svgPrefix . 'cache/' . $this->qrCachePrefix . hash("sha512", $shortURL) . '.svg'; diff --git a/src/lilURL.php b/src/lilURL.php index 0b62b7d..16f608d 100755 --- a/src/lilURL.php +++ b/src/lilURL.php @@ -36,6 +36,7 @@ class lilURL const PDO_PLACEHOLDER_LONG_URL = ':longURL'; const PDO_PLACEHOLDER_CREATED_BY = ':createdBy'; const PDO_PLACEHOLDER_REDIRECTS = ':redirects'; + const PDO_PLACEHOLDER_QR_CODE_SCANS = ':qrCodeScans'; const PDO_PLACEHOLDER_GROUP_ID = ':groupID'; const PDO_PLACEHOLDER_GROUP_NAME = ':groupName'; const PDO_PLACEHOLDER_UID = ':uid'; @@ -124,6 +125,9 @@ protected function trackHit($id) if (!$this->checkForBots()) { // track system redirect $this->incrementRedirectCount($id); + if (isset($_GET['qr'])) { + $this->incrementQRCodeScanCount($id); + } } $accountId = $this->getGaAccount(); @@ -754,7 +758,10 @@ public function deleteURL($urlID, $uid) public function resetRedirectCount($id) { return $this->db->update( self::TABLE_URLS, - array(ltrim(self::PDO_PLACEHOLDER_REDIRECTS, ':') => 0), + array( + ltrim(self::PDO_PLACEHOLDER_REDIRECTS, ':') => 0, + ltrim(self::PDO_PLACEHOLDER_QR_CODE_SCANS, ':') => 0, + ), self::WHERE_URL_ID, array(self::PDO_PLACEHOLDER_URL_ID => $id) ); @@ -983,4 +990,14 @@ private function incrementRedirectCount($id) { array(self::PDO_PLACEHOLDER_URL_ID => $id) ); } + + private function incrementQRCodeScanCount($id) { + return $this->db->run( + 'UPDATE ' + . self::TABLE_URLS + . ' SET qrCodeScans = qrCodeScans + 1 WHERE ' + . self::WHERE_URL_ID, + array(self::PDO_PLACEHOLDER_URL_ID => $id) + ); + } } diff --git a/www/templates/linkinfo.php b/www/templates/linkinfo.php index d819330..84089c3 100644 --- a/www/templates/linkinfo.php +++ b/www/templates/linkinfo.php @@ -41,6 +41,9 @@
Redirect Count
redirects ?? ''); ?>
+
QR Code Scans
+
qrCodeScans ?? ''); ?>
+
Last Redirect
lastRedirect) { diff --git a/www/templates/manage.php b/www/templates/manage.php index 6f0bd38..a0c7bd8 100644 --- a/www/templates/manage.php +++ b/www/templates/manage.php @@ -25,6 +25,7 @@ class="dcf-w-100% go_responsive_table flush-left dcf-table dcf-txt-sm" Long URL Group Redirects + QR Code Scans Last Redirect Created on Actions @@ -70,6 +71,9 @@ class="dcf-w-100% go_responsive_table flush-left dcf-table dcf-txt-sm" redirects ?? ''); ?> + + qrCodeScans ?? ''); ?> + @@ -112,8 +116,7 @@ class="dcf-btn dcf-btn-secondary" title="Reset redirect count for urlID ?? ''); ?> URL" - onclick="return confirm('Are you sure you want to reset the redirect count for \' - urlID ?? ''); ?>\'?');" + onclick=" return confirm('Are you sure you want to reset the redirect count for \'urlID ?? ''); ?>\'?');" > Reset Redirects @@ -152,8 +155,21 @@ class="dcf-btn dcf-btn-primary dcf-mr-6" > Add URL - - + +
+ + Note: +
    +
  • +
  • + "Redirects" is the total number of redirects, this includes the + "QR Codes Scans" as well as normal redirects. +
  • +
  • + Any QR Codes downloaded before October 2023 will not be counted in "QR Codes Scans", + please replace your old QR Codes to be able to take advantage of this metric. +
  • +