gabefromutah / gatsby-plugin-facebook-pixel

Gatsby plugin to add facebook pixel onto a site
15 stars 21 forks source link

Should ViewContent be triggered on every route change? #5

Open uriklar opened 4 years ago

uriklar commented 4 years ago

From the facebook pixel spec ViewContent is defined as:

A visit to a content page you care about (for example, a product page or landing page). View Content tells you if someone visits a web page, but not what they do on that web page.

The fact that it triggers on every route change makes it pretty much equal the PageView events. Do you think this is the desired behaviour? Thanks!

gabefromutah commented 3 years ago

Can you expand on "it triggers on every route change"?

limcolin commented 3 years ago

In gatsby-browser.js the ViewContent event is being made to fire onRouteUpdate.

This means it's firing on every page change - some of which are irrelevant.

I'm about to work on this now - the plan is it needs to check the route to only fire if it's a PDP url

exports.onRouteUpdate = function () {
  // Don't track while developing.
  if (process.env.NODE_ENV === `production` && typeof fbq === `function`) {
    fbq("track", "ViewContent");
  }
};