Logging User Activity in Oracle APEX: Who Did What, When, and Where?
If you want to understand how your Oracle APEX application is being used, it’s essential to log who accessed which page, when, and from where. This kind of tracking is crucial for building dashboards, analyzing user behavior, and improving security.
In this guide, I’ll show you step-by-step how to implement a comprehensive user activity log in Oracle APEX. This solution records every page view, including the user, timestamp, device, browser, operating system, and IP address.
Even if you’re new to APEX, you’ll find this approach easy to follow and adapt to your own projects!
1. Create the User Activity Log Table
First, we need a table to store all user activity.
Here’s the SQL code (run this in SQL Workshop > SQL Commands):
Here’s the SQL code (run this in SQL Workshop > SQL Commands):
Tip:
You can find SQL Workshop in the Oracle APEX menu. Use the “SQL Commands” or “SQL Scripts” section to run the statements above.
You can find SQL Workshop in the Oracle APEX menu. Use the “SQL Commands” or “SQL Scripts” section to run the statements above.
2. Create the Logging Procedure
Next, we’ll create a PL/SQL procedure that collects all the relevant information and writes it to our log table.
This procedure can be created in SQL Workshop > SQL Commands as well.
This procedure can be created in SQL Workshop > SQL Commands as well.
Tip:
After running this code, you’ll find your procedure under “SQL Workshop > Object Browser > Procedures”.
After running this code, you’ll find your procedure under “SQL Workshop > Object Browser > Procedures”.
3. Add an Application Process for Logging
To ensure every page view is logged, add an Application Process in your APEX app:
- Go to your application in the APEX App Builder.
- In the left menu, click Shared Components.
- Under Logic, click Application Processes.
- Click Create and enter:
- Name: user log of the application process
- Point: On Load: Before Header
- Sequence: 10 (so it runs first)
- Type: PL/SQL Code
Paste this code into the process:
Tip:
This process will run automatically on every page load, capturing all the information you need.
This process will run automatically on every page load, capturing all the information you need.
4. What’s Next? How to Use Your Log Data
Now, every page visit is recorded in your
You can use this data to:
USER_ACTIVITY_LOG
table.You can use this data to:
- Build dashboards showing user activity, popular pages, device/browser breakdowns, etc.
- Analyze trends, such as peak usage times or most active users.
- Troubleshoot issues by tracking user sessions and access patterns.
Where to find your data:
Go to SQL Workshop > Object Browser, select your table, and click “Data” to see the logs.
Go to SQL Workshop > Object Browser, select your table, and click “Data” to see the logs.
Extra Tips for Beginners
- If you’re new to Oracle APEX, explore the App Builder and SQL Workshop menus to get familiar with where to create tables, procedures, and processes.
- You can export your log data to Excel or use APEX’s built-in chart and report components to visualize your logs.
- For more advanced tracking, you can add custom event types (e.g., LOGIN, LOGOUT) by modifying the procedure.
- Test your logging: Visit different pages in your app and check if the logs are written correctly.
- Build your own dashboards: Use the logged data to create interactive reports and visualizations in APEX.
- Share your results: Show your team or stakeholders how users interact with your application.
With this approach, you’ll have a solid foundation for user analytics in any Oracle APEX project. Happy logging!
{fullWidth}