-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
refactor: exclude post preview page from data tracking #7582
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
refactor: exclude post preview page from data tracking #7582
Conversation
@GoldenSupremeSaltedFish: You must be a member of the halo-dev/milestone-maintainers GitHub team to set the milestone. If you believe you should be able to issue the /milestone command, please contact your Milestone Maintainers Team and have them propose you as an additional delegate for this responsibility. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
I don't particularly recommend implementing this by modifying the tracker script. Instead, I suggest simply not loading this script on the preview page at all. cc @guqing |
You can store an attribute in the ServerWebExchange in halo/application/src/main/java/run/halo/app/theme/router/PreviewRouterFunction.java Line 55 in 7b25791
|
Received. I will resolve this issue by June 26th. Thank you for your reminder |
Can this issue be assigned to me? |
Done |
This reverts commit 050749c.
- Introduced a new constant `IS_PREVIEW` in `ModelConst` to indicate preview mode. - Added `PreviewContextVariablesAcquirer` to provide context variables for preview mode. - Updated `HaloTrackerProcessor` to skip script injection when in preview mode. - Modified `PreviewRouterFunction` to set the preview mode attribute during post and single page rendering.
- 在 `ModelConst` 中添加 `IS_PREVIEW` 常量,用于指示预览模式。 - 更新 `PreviewContextVariablesAcquirer`,提供预览模式的上下文变量。 - 修改 `HaloTrackerProcessor`,在预览模式下跳过脚本注入。 - 更新 `PreviewRouterFunction`,为文章和单页渲染设置预览模式属性,并添加相关方法注释。
- Replace var with const/let - Use arrow functions - Simplify nested structures - Use modern JS features - Improve code maintainability Fixes SonarQube code quality issues.
done |
Frontend preview detection is no longer needed as the preview mode is now properly handled by HaloTrackerProcessor on the backend side through template variable checking. This follows the suggestion from @ruibaby that this file no longer needs modification for preview mode support.
- Remove frontend preview mode detection - Restore original var declarations and function syntax - Remove Chinese comments - Preview mode is now handled entirely by backend HaloTrackerProcessor As suggested by @ruibaby, this file no longer needs modification.
- Replace var with const/let declarations - Use arrow functions and modern syntax - Reduce function nesting depth - Extract helper functions for better separation - Use template strings and strict equality - Implement early return patterns Fixes SonarQube code quality issues without changing functionality. No preview detection logic added as per @ruibaby suggestion.
git checkout upstream/main -- application/src/main/resources/static/halo-tracker.js
git commit -m "Revert halo-tracker.js"
git push @guqing please help review the other parts. |
application/src/main/java/run/halo/app/theme/PreviewContextVariablesAcquirer.java
Outdated
Show resolved
Hide resolved
- Add SKIP_TRACKER constant in HaloTrackerProcessor - Remove IS_PREVIEW from ModelConst to avoid polluting global constants - Remove PreviewContextVariablesAcquirer for simpler implementation - Update preview router to use SKIP_TRACKER attribute This change ensures that post view counts are not incremented during preview, providing a cleaner and more maintainable solution. Fix halo-dev#1763
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: guqing, ruibaby The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind bug
/area core
/milestone 2.21.x
What this PR does / why we need it:
Prevents published post view counts from being incorrectly increased when previewing posts in the admin panel.
Previously, the preview mode would load the tracking script, which resulted in inflated view counts. This PR adds a condition to detect preview mode and disables the tracking logic to avoid counting views for unpublished content.
Does this PR introduce user-facing changes?