Event Time Variable for Facebook CAPI in Google Tag Manager

11 Feb, 2026

When you’re sending events to Facebook’s Conversions API through Google Tag Manager, you need to include a timestamp for each event. Here’s a simple JavaScript variable that does exactly that.

The Code

Variable Name: Event Time
Server-side variable name: event_time

function() {
  return Math.round(new Date().getTime() / 1000);
}
JavaScript

How to Use It

  1. In Google Tag Manager, go to Variables → New
  2. Select Custom JavaScript as the variable type
  3. Paste the code above
  4. Name it “JS – Event Time”
  5. Save the variable

Now you can use {{JS - Event Time}} in your Facebook CAPI tags wherever you need to pass the event_time parameter.

What It Does

This script captures the current time and converts it to a Unix timestamp (seconds since January 1, 1970), which is the format Facebook expects for the event_time parameter.

  • new Date().getTime() gets current time in milliseconds
  • Divide by 1000 to convert to seconds
  • Math.round() removes decimals

That’s it. Simple, clean, and ready to use in your Facebook server-side tracking setup.

Related Posts

Stop Double Conversions from Page Reloads in GTM

When someone refreshes your thank you page, your conversion tags fire again. This inflates your numbers and wastes ad budget. Here's a quick fix. The Problem User submits a form → lands on thank you page → conversion fires ✓ User hits refresh → conversion fires again...

read more

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Shibbir Ahmed

Hi, I’m here to help you learn Google Tag Manager and Google Analytics. Join thousands of other digital marketers and digital analysts in this exciting journey.
Book Meeting

Search Tags

Claim FREE Audit