mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-11-16 01:21:16 +01:00
Dynamic tracking services (#4690)
Added bean for both scarf and posthog followed documentation at https://docs.stirlingpdf.com/analytics-telemetry Co-authored-by: Connor Yoh <connor@stirlingpdf.com>
This commit is contained in:
parent
06efab5cb2
commit
1a3552d1f7
@ -271,9 +271,14 @@ public class AppConfig {
|
|||||||
return "NORMAL";
|
return "NORMAL";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(name = "disablePixel")
|
@Bean(name = "scarfEnabled")
|
||||||
public boolean disablePixel() {
|
public boolean scarfEnabled() {
|
||||||
return Boolean.parseBoolean(env.getProperty("DISABLE_PIXEL", "false"));
|
return applicationProperties.getSystem().isScarfEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean(name = "posthogEnabled")
|
||||||
|
public boolean posthogEnabled() {
|
||||||
|
return applicationProperties.getSystem().isPosthogEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(name = "machineType")
|
@Bean(name = "machineType")
|
||||||
|
|||||||
@ -320,6 +320,8 @@ public class ApplicationProperties {
|
|||||||
private String tessdataDir;
|
private String tessdataDir;
|
||||||
private Boolean enableAlphaFunctionality;
|
private Boolean enableAlphaFunctionality;
|
||||||
private Boolean enableAnalytics;
|
private Boolean enableAnalytics;
|
||||||
|
private Boolean enablePosthog;
|
||||||
|
private Boolean enableScarf;
|
||||||
private Datasource datasource;
|
private Datasource datasource;
|
||||||
private Boolean disableSanitize;
|
private Boolean disableSanitize;
|
||||||
private int maxDPI;
|
private int maxDPI;
|
||||||
@ -333,6 +335,18 @@ public class ApplicationProperties {
|
|||||||
public boolean isAnalyticsEnabled() {
|
public boolean isAnalyticsEnabled() {
|
||||||
return this.getEnableAnalytics() != null && this.getEnableAnalytics();
|
return this.getEnableAnalytics() != null && this.getEnableAnalytics();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPosthogEnabled() {
|
||||||
|
// Treat null as enabled when analytics is enabled
|
||||||
|
return this.isAnalyticsEnabled()
|
||||||
|
&& (this.getEnablePosthog() == null || this.getEnablePosthog());
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isScarfEnabled() {
|
||||||
|
// Treat null as enabled when analytics is enabled
|
||||||
|
return this.isAnalyticsEnabled()
|
||||||
|
&& (this.getEnableScarf() == null || this.getEnableScarf());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@ -56,7 +56,7 @@ public class PostHogService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void captureSystemInfo() {
|
private void captureSystemInfo() {
|
||||||
if (!applicationProperties.getSystem().isAnalyticsEnabled()) {
|
if (!applicationProperties.getSystem().isPosthogEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -67,7 +67,7 @@ public class PostHogService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void captureEvent(String eventName, Map<String, Object> properties) {
|
public void captureEvent(String eventName, Map<String, Object> properties) {
|
||||||
if (!applicationProperties.getSystem().isAnalyticsEnabled()) {
|
if (!applicationProperties.getSystem().isPosthogEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1898,6 +1898,8 @@ cookieBanner.preferencesModal.necessary.title.2=Always Enabled
|
|||||||
cookieBanner.preferencesModal.necessary.description=These cookies are essential for the website to function properly. They enable core features like setting your privacy preferences, logging in, and filling out forms—which is why they can’t be turned off.
|
cookieBanner.preferencesModal.necessary.description=These cookies are essential for the website to function properly. They enable core features like setting your privacy preferences, logging in, and filling out forms—which is why they can’t be turned off.
|
||||||
cookieBanner.preferencesModal.analytics.title=Analytics
|
cookieBanner.preferencesModal.analytics.title=Analytics
|
||||||
cookieBanner.preferencesModal.analytics.description=These cookies help us understand how our tools are being used, so we can focus on building the features our community values most. Rest assured—Stirling PDF cannot and will never track the content of the documents you work with.
|
cookieBanner.preferencesModal.analytics.description=These cookies help us understand how our tools are being used, so we can focus on building the features our community values most. Rest assured—Stirling PDF cannot and will never track the content of the documents you work with.
|
||||||
|
cookieBanner.preferencesModal.analytics.posthog.label=PostHog Analytics
|
||||||
|
cookieBanner.preferencesModal.analytics.scarf.label=Scarf Pixel
|
||||||
|
|
||||||
#scannerEffect
|
#scannerEffect
|
||||||
scannerEffect.title=Scanner Effect
|
scannerEffect.title=Scanner Effect
|
||||||
|
|||||||
@ -1898,6 +1898,8 @@ cookieBanner.preferencesModal.necessary.title.2=Always Enabled
|
|||||||
cookieBanner.preferencesModal.necessary.description=These cookies are essential for the website to function properly. They enable core features like setting your privacy preferences, logging in, and filling out forms—which is why they can’t be turned off.
|
cookieBanner.preferencesModal.necessary.description=These cookies are essential for the website to function properly. They enable core features like setting your privacy preferences, logging in, and filling out forms—which is why they can’t be turned off.
|
||||||
cookieBanner.preferencesModal.analytics.title=Analytics
|
cookieBanner.preferencesModal.analytics.title=Analytics
|
||||||
cookieBanner.preferencesModal.analytics.description=These cookies help us understand how our tools are being used, so we can focus on building the features our community values most. Rest assured—Stirling PDF cannot and will never track the content of the documents you work with.
|
cookieBanner.preferencesModal.analytics.description=These cookies help us understand how our tools are being used, so we can focus on building the features our community values most. Rest assured—Stirling PDF cannot and will never track the content of the documents you work with.
|
||||||
|
cookieBanner.preferencesModal.analytics.posthog.label=PostHog Analytics
|
||||||
|
cookieBanner.preferencesModal.analytics.scarf.label=Scarf Pixel
|
||||||
|
|
||||||
#scannerEffect
|
#scannerEffect
|
||||||
scannerEffect.title=Scanner Effect
|
scannerEffect.title=Scanner Effect
|
||||||
|
|||||||
@ -109,7 +109,9 @@ system:
|
|||||||
showUpdateOnlyAdmin: false # only admins can see when a new update is available, depending on showUpdate it must be set to 'true'
|
showUpdateOnlyAdmin: false # only admins can see when a new update is available, depending on showUpdate it must be set to 'true'
|
||||||
customHTMLFiles: false # enable to have files placed in /customFiles/templates override the existing template HTML files
|
customHTMLFiles: false # enable to have files placed in /customFiles/templates override the existing template HTML files
|
||||||
tessdataDir: /usr/share/tessdata # path to the directory containing the Tessdata files. This setting is relevant for Windows systems. For Windows users, this path should be adjusted to point to the appropriate directory where the Tessdata files are stored.
|
tessdataDir: /usr/share/tessdata # path to the directory containing the Tessdata files. This setting is relevant for Windows systems. For Windows users, this path should be adjusted to point to the appropriate directory where the Tessdata files are stored.
|
||||||
enableAnalytics: null # set to 'true' to enable analytics, set to 'false' to disable analytics; for enterprise users, this is set to true
|
enableAnalytics: null # Master toggle for analytics: set to 'true' to enable all analytics, 'false' to disable all analytics, or leave as 'null' to prompt admin on first launch
|
||||||
|
enablePosthog: null # Enable PostHog analytics (open-source product analytics): set to 'true' to enable, 'false' to disable, or 'null' to enable by default when analytics is enabled
|
||||||
|
enableScarf: null # Enable Scarf pixel: set to 'true' to enable, 'false' to disable, or 'null' to enable by default when analytics is enabled
|
||||||
enableUrlToPDF: false # Set to 'true' to enable URL to PDF, INTERNAL ONLY, known security issues, should not be used externally
|
enableUrlToPDF: false # Set to 'true' to enable URL to PDF, INTERNAL ONLY, known security issues, should not be used externally
|
||||||
disableSanitize: false # set to true to disable Sanitize HTML; (can lead to injections in HTML)
|
disableSanitize: false # set to true to disable Sanitize HTML; (can lead to injections in HTML)
|
||||||
maxDPI: 500 # Maximum allowed DPI for PDF to image conversion
|
maxDPI: 500 # Maximum allowed DPI for PDF to image conversion
|
||||||
|
|||||||
@ -3,6 +3,19 @@ import './cookieconsent.umd.js';
|
|||||||
// Enable dark mode
|
// Enable dark mode
|
||||||
document.documentElement.classList.add('cc--darkmode');
|
document.documentElement.classList.add('cc--darkmode');
|
||||||
|
|
||||||
|
// Build analytics services dynamically based on backend config
|
||||||
|
const analyticsServices = {};
|
||||||
|
if (typeof posthogEnabled !== 'undefined' && posthogEnabled) {
|
||||||
|
analyticsServices.posthog = {
|
||||||
|
label: cookieBannerPreferencesModalPosthogLabel
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (typeof scarfEnabled !== 'undefined' && scarfEnabled) {
|
||||||
|
analyticsServices.scarf = {
|
||||||
|
label: cookieBannerPreferencesModalScarfLabel
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
CookieConsent.run({
|
CookieConsent.run({
|
||||||
guiOptions: {
|
guiOptions: {
|
||||||
consentModal: {
|
consentModal: {
|
||||||
@ -22,7 +35,9 @@ CookieConsent.run({
|
|||||||
necessary: {
|
necessary: {
|
||||||
readOnly: true
|
readOnly: true
|
||||||
},
|
},
|
||||||
analytics: {}
|
analytics: {
|
||||||
|
services: analyticsServices
|
||||||
|
}
|
||||||
},
|
},
|
||||||
language: {
|
language: {
|
||||||
default: "en",
|
default: "en",
|
||||||
|
|||||||
@ -168,14 +168,51 @@
|
|||||||
<!-- Bootstrap Icons -->
|
<!-- Bootstrap Icons -->
|
||||||
<link rel="stylesheet" th:href="@{'/css/bootstrap-icons.min.css'}">
|
<link rel="stylesheet" th:href="@{'/css/bootstrap-icons.min.css'}">
|
||||||
|
|
||||||
<!-- Pixel, doesn't collect any PII-->
|
<!-- Scarf Pixel - loaded dynamically based on cookie consent -->
|
||||||
<img th:if="${!@disablePixel}" referrerpolicy="no-referrer-when-downgrade"
|
<script th:inline="javascript">
|
||||||
th:src="'https://pixel.stirlingpdf.com/a.png?x-pxid=4f5fa02f-a065-4efb-bb2c-24509a4b6b92'
|
const posthogEnabled = /*[[${@posthogEnabled}]]*/ false;
|
||||||
|
const scarfEnabled = /*[[${@scarfEnabled}]]*/ false;
|
||||||
|
const scarfPixelUrl = /*[['https://pixel.stirlingpdf.com/a.png?x-pxid=4f5fa02f-a065-4efb-bb2c-24509a4b6b92'
|
||||||
+ '&machineType=' + ${@machineType}
|
+ '&machineType=' + ${@machineType}
|
||||||
+ '&appVersion=' + ${@appVersion}
|
+ '&appVersion=' + ${@appVersion}
|
||||||
+ '&licenseType=' + ${@license}
|
+ '&licenseType=' + ${@license}
|
||||||
+ '&loginEnabled=' + ${@loginEnabled}"
|
+ '&loginEnabled=' + ${@loginEnabled}]]*/ '';
|
||||||
style="position: absolute; visibility: hidden;" />
|
|
||||||
|
function loadScarfPixel() {
|
||||||
|
if (!scarfEnabled || !window.CookieConsent) return;
|
||||||
|
|
||||||
|
// Check if scarf service is accepted
|
||||||
|
if (window.CookieConsent.acceptedService('scarf', 'analytics')) {
|
||||||
|
// Remove any existing scarf pixel
|
||||||
|
const existingPixel = document.getElementById('scarf-pixel');
|
||||||
|
if (existingPixel) existingPixel.remove();
|
||||||
|
|
||||||
|
// Create and inject the pixel
|
||||||
|
const img = document.createElement('img');
|
||||||
|
img.id = 'scarf-pixel';
|
||||||
|
img.src = scarfPixelUrl;
|
||||||
|
img.referrerPolicy = 'no-referrer-when-downgrade';
|
||||||
|
img.style.position = 'absolute';
|
||||||
|
img.style.visibility = 'hidden';
|
||||||
|
document.body.appendChild(img);
|
||||||
|
} else {
|
||||||
|
// Remove pixel if user rejected
|
||||||
|
const existingPixel = document.getElementById('scarf-pixel');
|
||||||
|
if (existingPixel) existingPixel.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Load pixel on consent events
|
||||||
|
window.addEventListener('cc:onConsent', loadScarfPixel);
|
||||||
|
window.addEventListener('cc:onChange', loadScarfPixel);
|
||||||
|
|
||||||
|
// Try to load on page load if consent already given
|
||||||
|
if (document.readyState === 'loading') {
|
||||||
|
document.addEventListener('DOMContentLoaded', loadScarfPixel);
|
||||||
|
} else {
|
||||||
|
loadScarfPixel();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
<!-- Custom -->
|
<!-- Custom -->
|
||||||
<link rel="stylesheet" th:href="@{'/css/general.css'}">
|
<link rel="stylesheet" th:href="@{'/css/general.css'}">
|
||||||
@ -221,7 +258,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.CookieConsent.acceptedCategory('analytics')?
|
window.CookieConsent.acceptedService('posthog', 'analytics')?
|
||||||
posthog.opt_in_capturing() : posthog.opt_out_capturing();
|
posthog.opt_in_capturing() : posthog.opt_out_capturing();
|
||||||
}
|
}
|
||||||
const stirlingPDFLabel = /*[[${@StirlingPDFLabel}]]*/ '';
|
const stirlingPDFLabel = /*[[${@StirlingPDFLabel}]]*/ '';
|
||||||
@ -248,6 +285,8 @@
|
|||||||
const cookieBannerPreferencesModalNecessaryDescription = /*[[#{cookieBanner.preferencesModal.necessary.description}]]*/ "";
|
const cookieBannerPreferencesModalNecessaryDescription = /*[[#{cookieBanner.preferencesModal.necessary.description}]]*/ "";
|
||||||
const cookieBannerPreferencesModalAnalyticsTitle = /*[[#{cookieBanner.preferencesModal.analytics.title}]]*/ "";
|
const cookieBannerPreferencesModalAnalyticsTitle = /*[[#{cookieBanner.preferencesModal.analytics.title}]]*/ "";
|
||||||
const cookieBannerPreferencesModalAnalyticsDescription = /*[[#{cookieBanner.preferencesModal.analytics.description}]]*/ "";
|
const cookieBannerPreferencesModalAnalyticsDescription = /*[[#{cookieBanner.preferencesModal.analytics.description}]]*/ "";
|
||||||
|
const cookieBannerPreferencesModalPosthogLabel = /*[[#{cookieBanner.preferencesModal.analytics.posthog.label}]]*/ "";
|
||||||
|
const cookieBannerPreferencesModalScarfLabel = /*[[#{cookieBanner.preferencesModal.analytics.scarf.label}]]*/ "";
|
||||||
|
|
||||||
if (analyticsEnabled) {
|
if (analyticsEnabled) {
|
||||||
!function (t, e) {
|
!function (t, e) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user