2022-12-22 20:55:30 -05:00
|
|
|
/*!
|
2023-03-16 05:47:59 -05:00
|
|
|
* @source: https://github.com/kytta/share2fedi/blob/main/lib/count.js
|
2022-12-22 20:55:30 -05:00
|
|
|
*
|
|
|
|
* @licstart The following is the entire license notice for the
|
|
|
|
* JavaScript code in this page.
|
|
|
|
*
|
2023-03-16 09:20:56 -05:00
|
|
|
* share2fedi - Instance-agnostic share page for the Fediverse.
|
|
|
|
* Copyright (C) 2023 Nikita Karamov <me@kytta.dev>
|
2022-12-22 20:55:30 -05:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* @licend The above is the entire license notice
|
|
|
|
* for the JavaScript code in this page.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
*/
|
|
|
|
|
2023-03-16 09:20:56 -05:00
|
|
|
// This is the analytics code for Share₂Fedi. It just sends a beacon
|
|
|
|
// to GoatCounter with hardcoded path. This is way more lightweight, performant
|
2022-12-22 20:55:30 -05:00
|
|
|
// and privacy-friendly than the default GC script.
|
|
|
|
|
2022-12-22 21:08:22 -05:00
|
|
|
if (
|
|
|
|
window.location.host === "s2f.kytta.dev" ||
|
|
|
|
window.location.host === "share2fedi.kytta.dev"
|
|
|
|
) {
|
2023-03-01 06:42:33 -05:00
|
|
|
// eslint-disable-next-line unicorn/prefer-top-level-await
|
|
|
|
fetch("//gc.zgo.at/", { method: "HEAD" }).then((result) => {
|
2023-03-16 09:20:56 -05:00
|
|
|
// Check if the default GC URL resolves
|
|
|
|
// This allows us to not track people with ad blockers
|
2023-03-01 06:42:33 -05:00
|
|
|
if (!result.ok) {
|
|
|
|
return;
|
|
|
|
}
|
2022-12-22 21:05:09 -05:00
|
|
|
|
2023-03-01 06:42:33 -05:00
|
|
|
const screen = encodeURIComponent(
|
|
|
|
[
|
|
|
|
window.screen.width,
|
|
|
|
window.screen.height,
|
|
|
|
window.devicePixelRatio || 1,
|
2023-03-17 08:06:30 -05:00
|
|
|
].join(","),
|
2023-03-01 06:42:33 -05:00
|
|
|
);
|
2022-12-22 20:55:30 -05:00
|
|
|
|
2023-03-01 06:42:33 -05:00
|
|
|
const random = encodeURIComponent(Math.random().toString(36).slice(2));
|
2022-12-22 20:55:30 -05:00
|
|
|
|
2023-03-01 06:42:33 -05:00
|
|
|
navigator.sendBeacon(
|
2023-03-17 08:06:30 -05:00
|
|
|
`https://share2fedi.goatcounter.com/count?p=%2F&s=${screen}&b=0&rnd=${random}`,
|
2023-03-01 06:42:33 -05:00
|
|
|
);
|
|
|
|
});
|
2022-12-22 21:08:22 -05:00
|
|
|
}
|