Track all Firestore write activity in Firestore

Created on .

Read in 1 minute.


As part of a little side project, I wanted to log all Firestore writes for a user to a user specific collection that I can use to display a user’s activity. I was able to accomplish this using Audit Logs, Pub/Sub, and Cloud Functions.


  • Log all Firestore writes for a user, ignore reads
  • Access the writes as an activity collection for the user, users/{userId}/activity


There are a few moving parts to this solution, but it’s pretty automatic.

Firestore Audit Logs to Collection

Firestore Audit Logs to Collection

  1. Audit Logs are enabled for Firestore writes
Enable Firestore Audit Logs

Enable Firestore Audit Logs

  1. Logs are sent to a Pub/Sub topic via a sink
Create PubSub Sink

Create PubSub Sink

  1. Cloud Function is triggered by Pub/Sub message
import * as firebaseAdmin from "firebase-admin";
import * as functions from "firebase-functions";

export default functions.pubsub
.onPublish(async (message) => {
const { data } = message;
const { timestamp, protoPayload } = JSON.parse(
Buffer.from(data, "base64").toString()

const uid =

const writes = protoPayload.request.writes;

const activityRef = firebaseAdmin

await Promise.all(
// eslint-disable-next-line @typescript-eslint/no-explicit-any any) => {
activityRef.add({ write, timestamp });
  1. Cloud Function writes to Firestore
User Collection Containing Activity

User Collection Containing Activity


La Sportiva Cyklon Cross GTX Review


Delete Old GitHub Forks


Get the RSS feeds: All, Run, Code.