How to Track and Report Timestamps in GA4 with Google Tag Manager

Table of contents
- Why Track Timestamps in GA4?
- Step 1: Set Up GA4 and Google Tag Manager
- Step 2: Add a Timestamp Parameter in GTM
- Step 3: Verify Timestamp Data in GA4
- Step 4: Create a Custom Dimension for Timestamps
- Step 5: Use Timestamp Data in Explorations
- Common Troubleshooting Tips
- Why Use GA4 + GTM for Timestamps?
- Bonus: Push Timestamp Data to Google Sheets in Real Time

Ever wanted to know the exact time users engage with your website? While GA4 doesn’t offer built-in timestamp tracking, you can set it up using Google Tag Manager (GTM). This step-by-step guide will show you how to capture precise timestamps for events and page views, making your analytics even more insightful.
Why Track Timestamps in GA4?
Timestamps are invaluable for:
Pinpointing when users interact with your site.
Analyzing user behavior during specific campaigns or external events.
Syncing analytics with other tools like CRMs or dashboards for deeper insights.
Step 1: Set Up GA4 and Google Tag Manager
Before starting, ensure your GA4 property is linked to your site, and GTM is installed. You’ll also need a GA4 Configuration Tag with your Measurement ID.
Step 2: Add a Timestamp Parameter in GTM
To track timestamps, create a custom JavaScript variable in GTM and pass it to your GA4 event tags.
Create a Timestamp Variable:
In GTM, go to Variables > New > Custom JavaScript.
Add this script to format timestamps as
yyyy-MM-dd HH:mm:ss
:function() { var date = new Date(); var yyyy = date.getFullYear(); var MM = String(date.getMonth() + 1).padStart(2, '0'); var dd = String(date.getDate()).padStart(2, '0'); var HH = String(date.getHours()).padStart(2, '0'); var mm = String(date.getMinutes()).padStart(2, '0'); var ss = String(date.getSeconds()).padStart(2, '0'); return yyyy + '-' + MM + '-' + dd + ' ' + HH + ':' + mm + ':' + ss; }
Save the variable as
Formatted Timestamp
.
Add the Timestamp Parameter to Your GA4 Event Tag:
If you don't already have a GA4 Event Tag, create one:
In GTM, click New Tag and select Google Analytics: GA4 Event.
Enter an event name (e.g.,
page_view
) and associate it with your GA4 Configuration Tag.
Open the Event Tag and scroll to Event Parameters.
Click Add Row:
Parameter Name:
timestamp
Value:
{{Formatted Timestamp}}
Save and publish your GTM container.
Step 3: Verify Timestamp Data in GA4
To confirm the setup works, use DebugView in GA4 or Preview in GTM.
Enable GTM Debug Mode:
- Preview your GTM setup or append
?debug_mode=1
to your site’s URL.
- Preview your GTM setup or append
Check DebugView:
Go to Admin > DebugView in GA4.
Trigger events (e.g., page views) on your site.
Verify that the
timestamp
parameter appears for your events.
Step 4: Create a Custom Dimension for Timestamps
GA4 requires you to register timestamp
as a custom dimension to use it in reports.
Go to Admin > Custom Definitions in GA4.
Click Create Custom Dimension.
Fill in the details:
Dimension Name:
Timestamp
Scope: Event
Event Parameter:
timestamp
Save the dimension.
Note: Custom dimensions only start collecting data after creation; past data won’t be included.
Step 5: Use Timestamp Data in Explorations
Once data propagates (24-48 hours), use Explorations to analyze timestamps.
Create an Exploration:
Go to Explore in GA4 and start a Free Form Exploration.
Add
Timestamp
as a Dimension.Add metrics like
Event Count
.
Visualize Data:
Filter by specific events (e.g.,
page_view
).Use tables or charts to see timestamped activity.
Common Troubleshooting Tips
Timestamp Not Showing in DebugView:
- Ensure the
Formatted Timestamp
variable is added correctly to your GA4 Event Tag.
- Ensure the
Timestamp Missing in Reports:
Verify the custom dimension setup in GA4.
Wait 24-48 hours for data to propagate.
DebugView Works, but Explorations Don’t:
- Confirm that the
timestamp
dimension is included in your Exploration setup.
- Confirm that the
Why Use GA4 + GTM for Timestamps?
This setup combines GA4’s powerful analytics with GTM’s flexibility, offering:
Precise tracking of user behavior.
Easy integration with other tools.
Cost-effective solutions using free tools.
Bonus: Push Timestamp Data to Google Sheets in Real Time
If you want to avoid waiting next data for data to appear in GA4 reports and push timestamp data directly to a Google Sheet in real time, follow these steps:
1. Create a Google Sheets Document
Open Google Sheets and create a new spreadsheet.
Add headers in the first row, such as:
Timestamp | Page URL
2. Set Up a Webhook with Google Apps Script
Open Extensions > Apps Script in the spreadsheet.
Replace the default code with:
function doPost(e) { var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var params = JSON.parse(e.postData.contents); sheet.appendRow([params.timestamp, params.page]); return ContentService.createTextOutput(JSON.stringify({status: 'success'})) .setMimeType(ContentService.MimeType.JSON); }
Deploy the script as a Web App:
Execute as: Me
Who has access: Anyone
Copy the Web App URL.
3. Update GTM to Push Data
Create a Custom HTML Tag in GTM:
<script> var payload = { page: document.location.href, timestamp: new Date().toISOString() }; fetch('YOUR_WEB_APP_URL', { method: 'POST', mode: 'no-cors', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); </script>
Replace
YOUR_WEB_APP_URL
with the URL from your Apps Script deployment.Attach a trigger (e.g., All Pages) to fire the tag.
4. Test the Setup
Use GTM Preview Mode to ensure the tag fires correctly.
Verify that data appears in your Google Sheet.
Conclusion
With a few simple steps, you can add timestamps to your GA4 analytics and even push this data to Google Sheets in real time. This guide helps you set up, test, and enhance your analytics seamlessly—ensuring your data is actionable and valuable.
Have questions or tips? Let me know in the comments!
Conclusion
With a few simple steps, you can add timestamps to your GA4 analytics and unlock deeper insights into user behavior. This guide helps you set up, test, and report timestamps seamlessly—ensuring your analytics are more actionable than ever.
Have questions or tips? Let me know in the comments!
Subscribe to my newsletter
Read articles from Roman Vasilenko directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Roman Vasilenko
Roman Vasilenko
I am a full-stack software developer passionate about SaaS, DeFi, and Web3 technologies. My obsession with learning and experimenting took me places. I lived in 4 different countries and 5 cities, launched a few good and not so much IT startups, worked in digital marketing, tried biohacking and sleep deprivation, and many more. Follow or message me, I'm open to any connections.