Leverage proxy/redirect to track retrieval of RSS feed file?

Context:

  • Site name. Example: ringo.de-smet.name

I have Plausible Analytics integrated into my site. All the pages on my site are tracked (in a privacy friendly manner) expect my RSS feed file.

Plausible has an Events API which allows sending tracking events yourself:

Is it possible to use the Netlify proxy/redirects option to still let Netlify serve the feed.xml file, but also execute a trigger on this Events API on every retrieval of the RSS feed file?

R.

Hey @ringods

I believe the only option here is to use an Edge Function on the /feed.xml path

[[edge_functions]]
  path = "/feed.xml"
  function = "feed"

The function can make a fetch request to the API, set cookies, etc. then serve the file. Basic example

export default async(req, { cookies, log }) => {
  try {
    await fetch("https://api.example.com", {
      method: 'GET',
      headers: {
        'X-From': 'Netlify',  // If you need headers
      },
      body: "blah blah blah"
    })
    // Set a cookie if you want
    cookies.set({
      name: 'feed',
      value: "Testing",
    })
  } catch(e) {
    log(e)
  }
  // now the file will load (if it exists)
}