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);
}JavaScriptHow to Use It
- In Google Tag Manager, go to Variables → New
- Select Custom JavaScript as the variable type
- Paste the code above
- Name it “JS – Event Time”
- 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.

0 Comments