Skip to content

Qr code tracking #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/goURL.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand All @@ -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` (
Expand Down
4 changes: 2 additions & 2 deletions src/goController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down
19 changes: 18 additions & 1 deletion src/lilURL.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
);
Expand Down Expand Up @@ -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)
);
}
}
3 changes: 3 additions & 0 deletions www/templates/linkinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<dt>Redirect Count</dt>
<dd class="dcf-pl-6"><?php echo htmlspecialchars($link->redirects ?? ''); ?></dd>

<dt>QR Code Scans</dt>
<dd class="dcf-pl-6"><?php echo htmlspecialchars($link->qrCodeScans ?? ''); ?></dd>

<dt>Last Redirect</dt>
<dd class="dcf-pl-6"><?php
if ($link->lastRedirect) {
Expand Down
24 changes: 20 additions & 4 deletions www/templates/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class="dcf-w-100% go_responsive_table flush-left dcf-table dcf-txt-sm"
<th scope="col">Long URL</th>
<th scope="col">Group</th>
<th scope="col">Redirects</th>
<th scope="col">QR Code Scans</th>
<th scope="col">Last Redirect</th>
<th scope="col">Created&nbsp;on</th>
<th scope="col" data-searchable="false" data-orderable="false">Actions</th>
Expand Down Expand Up @@ -70,6 +71,9 @@ class="dcf-w-100% go_responsive_table flush-left dcf-table dcf-txt-sm"
<td data-header="Redirects">
<?php echo htmlspecialchars($url->redirects ?? ''); ?>
</td>
<td data-header="QR Code Scans">
<?php echo htmlspecialchars($url->qrCodeScans ?? ''); ?>
</td>
<td
data-header="LastRedirect"
<?php if ($lastRedirect): ?>
Expand Down Expand Up @@ -112,8 +116,7 @@ class="dcf-btn dcf-btn-secondary"
title="Reset redirect count for <?php
echo htmlspecialchars($url->urlID ?? '');
?> URL"
onclick="return confirm('Are you sure you want to reset the redirect count for \'
<?php echo htmlspecialchars($url->urlID ?? ''); ?>\'?');"
onclick=" return confirm('Are you sure you want to reset the redirect count for \'<?php echo htmlspecialchars($url->urlID ?? ''); ?>\'?');"
>
Reset Redirects
</a>
Expand Down Expand Up @@ -152,8 +155,21 @@ class="dcf-btn dcf-btn-primary dcf-mr-6"
>
Add URL
</a>
<span class="dcf-d-inline-block dcf-mt-6 dcf-mt-0@md dcf-form-help">
<?php echo GoController::URL_AUTO_PURGE_NOTICE; ?>
</div>
<div>
<span class="dcf-d-inline-block dcf-m-0 dcf-form-help">
Note:
<ul>
<li><?php echo GoController::URL_AUTO_PURGE_NOTICE; ?></li>
<li>
"Redirects" is the total number of redirects, this includes the
"QR Codes Scans" as well as normal redirects.
</li>
<li>
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.
</li>
</ul>
</span>
</div>
</div>
Expand Down