Skip to content
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

Addition of Logs for Page Viewing Events #4775

Open
1 task done
alexenedino opened this issue Jan 15, 2024 · 5 comments
Open
1 task done

Addition of Logs for Page Viewing Events #4775

alexenedino opened this issue Jan 15, 2024 · 5 comments

Comments

@alexenedino
Copy link

Describe the feature you'd like

Hello,

I am an avid user of Bookstrack and have actively been using the audit log feature to track modifications. However, I've noticed that currently, we don't have the ability to track page viewing events or shelf openings in Bookstack.

I believe that adding this information to the logs would be extremely beneficial for the user community. Being able to track who viewed certain pages or opened shelves would be useful for various use cases, especially in collaborative environments.

Describe the benefits this would bring to existing BookStack users

Enhanced Traceability:

Outcome: Users can have a comprehensive view of interactions within BookStack.
Benefit: Improved accountability and traceability as users can track who viewed specific pages, aiding in collaborative projects and knowledge sharing.
Improved Collaboration:

Outcome: Facilitates collaboration by providing insights into user engagement with content.
Benefit: Users can understand how team members interact with shared information, fostering collaboration, and enabling more effective communication.
Content Popularity Insights:

Outcome: Enables tracking of popular pages or shelves.
Benefit: Users gain insights into the most accessed content, helping in content curation and prioritization of updates or improvements based on actual usage patterns.
User Behavior Analysis:

Outcome: Users can analyze how others navigate through the knowledge base.
Benefit: Understanding user behavior helps in optimizing the structure and organization of information, ensuring a more intuitive and user-friendly experience.
Benefits of Adding Shelf Opening Events to Logs:

Usage Analytics for Shelves:

Outcome: Users can track which shelves are being actively accessed.
Benefit: Administrators and content creators can analyze the popularity of different shelves, tailoring content placement and organization to meet user needs more effectively.
Customization and Personalization:

Outcome: Users can tailor shelves based on observed user interactions.
Benefit: Individuals or teams can customize their BookStack experience, creating more personalized and efficient workflows based on the actual usage of shelves.
Identification of Underutilized Content:

Outcome: Reveals shelves that are seldom opened.
Benefit: Users can identify underutilized content and either update it, remove it, or reorganize it to enhance the overall usefulness of the knowledge base.
By incorporating these features into BookStack, users gain valuable insights into user behavior, content popularity, and collaboration patterns, ultimately enhancing the utility and effectiveness of the platform.

Can the goal of this request already be achieved via other means?

No.

Currently, the requested goal of tracking page viewing events and shelf openings cannot be achieved through other means within BookStack. The existing methods, such as the audit log feature, primarily focus on modifications and changes made within the platform. The requested approach would complement these existing methods by providing additional insights into user interactions, content popularity, and the utilization of shelves, which are not covered by the current auditing capabilities.

In essence, the proposed feature introduces a new layer of information that enhances the overall understanding of how users engage with the content and structure within BookStack, filling a gap that is not addressed by the existing methods.

Have you searched for an existing open/closed issue?

  • I have searched for existing issues and none cover my fundamental request

How long have you been using BookStack?

1 to 5 years

Additional context

No response

@ssddanbrown
Copy link
Member

Hi @alexenedino,
This is closely related to existing closed issues #1772 and #518, and also relevant to existing open issue #3204.

To achieve the described benefits and desires, we'd need a fair bit more than just logging view events to the audit log.
I'm not keen on expanding the audit log to view events, and would prefer to keep the scope to change events to keep the amount of audit events, and uses of our activity/audit system (like webhooks) reasonable.

As mentioned in some of those other issues, we do already track views in the system rolled up per-user-per-item. You could use this existing table externally, or integrate an actual analytics solution if you want more detail.

I can understand the desire of native analytics in BookStack, but the system is used in quite a few different ways, by different configurations of users, that it'd open up a whole new scope of possible desires and requests to have analytics that suit their specific environments. I'm not too keen on jumping into that while external solutions could be used which would probably do a much better job, while configurable to that instance's desires/usage/setup.

@ademstan
Copy link

+1

We recently gave access to "public" which is still members of our team but they are not supposed to have access to everything. We missed the chapter permissions and some unauthorized users may have viewed pages they were not authorized to.

If we had page_view & page_export events as part of the audit log, we could trace who viewed the pages and exported them.

@networkjutsu
Copy link

+1

From a security perspective, it'll be nice to have a log of what the user did while logged in. I was looking for some type of log to see what the users when they logged in but it seems like the audit log is insufficient.

@tsykkel
Copy link

tsykkel commented Nov 13, 2024

This is meant for a virtual machine install.

I also had a need to see what a user viewed in their session. As the "views" table in the "bookstack" database in MySQL marked down each view, I created a sort of workaround.

MySQL supports database triggers. What I did was create a new database and created a table in the database, where the trigger will mark down the user and the page/book/bookshelf/chapter the user viewed and when they viewed it. As MySQL does not support inserting table names as variables, I resorted to a "simple" solution.

CREATE DATABASE view_logs;

USE view_logs;

CREATE TABLE view_events (
	id INT AUTO_INCREMENT PRIMARY KEY,
	user_id INT NOT NULL,
	username VARCHAR(255),
	content_id INT NOT NULL,
	content_name VARCHAR(255),
	content_type VARCHAR(50),
	time_of_viewing TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
);

USE bookstack;

DELIMITER //

CREATE TRIGGER after_views_update
AFTER UPDATE ON views
FOR EACH ROW
BEGIN
    DECLARE user_name VARCHAR(255);
    DECLARE content_title VARCHAR(255);
    
    IF OLD.updated_at <> NEW.updated_at THEN
        IF NEW.viewable_type = 'bookshelf' THEN
            SELECT name INTO content_title FROM bookshelves WHERE id = NEW.viewable_id LIMIT 1;
        ELSEIF NEW.viewable_type = 'book' THEN
            SELECT name INTO content_title FROM books WHERE id = NEW.viewable_id LIMIT 1;
        ELSEIF NEW.viewable_type = 'page' THEN
            SELECT name INTO content_title FROM pages WHERE id = NEW.viewable_id LIMIT 1;
        ELSEIF NEW.viewable_type = 'chapter' THEN
            SELECT name INTO content_title FROM chapters WHERE id = NEW.viewable_id LIMIT 1;
        END IF;
    SELECT name INTO user_name FROM users WHERE id = NEW.user_id LIMIT 1;
    INSERT INTO view_logs.view_events (user_id, username, content_id, content_name, content_type)
    VALUES (NEW.user_id, user_name, NEW.viewable_id, content_title, NEW.viewable_type);
    END IF;
END//

CREATE TRIGGER after_views_insert
AFTER INSERT ON views
FOR EACH ROW
BEGIN
    DECLARE user_name VARCHAR(255);
    DECLARE content_title VARCHAR(255);
    
    IF NEW.viewable_type = 'bookshelf' THEN
        SELECT name INTO content_title FROM bookshelves WHERE id = NEW.viewable_id LIMIT 1;
    ELSEIF NEW.viewable_type = 'book' THEN
        SELECT name INTO content_title FROM books WHERE id = NEW.viewable_id LIMIT 1;
    ELSEIF NEW.viewable_type = 'page' THEN
        SELECT name INTO content_title FROM pages WHERE id = NEW.viewable_id LIMIT 1;
    ELSEIF NEW.viewable_type = 'chapter' THEN
        SELECT name INTO content_title FROM chapters WHERE id = NEW.viewable_id LIMIT 1;
    END IF;
    SELECT name INTO user_name FROM users WHERE id = NEW.user_id LIMIT 1;
    INSERT INTO view_logs.view_events (user_id, username, content_id, content_name, content_type)
    VALUES (NEW.user_id, user_name, NEW.viewable_id, content_title, NEW.viewable_type);
END//

DELIMITER ;

The output is as follows:
image

As my use case is small enough, the impact this piece of code gives is unnoticeable on the performance and fits my needs.
I have not tested this on a large scale deployment. Use at own risk.

I hope this gives some ideas for others who are looking for a workaround.

@ssddanbrown
Copy link
Member

@alexenedino That's a smart & neat workaround for those that want this at a database level, thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants