Pixel count views on data only next.js page

Hello,

I am having issues where I see a bunch of requests sent to the builder.io pixel with the event that is what I believe is tracking for a page view. Screenshots provided.

Why is pixel tracking anything on a page that displays only data models that are queried via content API?

I am using only content API for that page and not the “RenderBuilderContent” component.

I am using next.js with an app router and a layout that is querying “footer”, “header” and “navigation” models, all of which are data models. Additionally, I have filtering and sorting that are calling only the data portion of the model and on every URL change (URL params are used for filtering and sorting) a call is made.

Builder public API key
197884cda72d4f8780e848822de859eb

Screenshots or video link

Code stack you are integrating Builder with
NextJS app router

Hello @nikola,

Welcome to the Builder.io forum post.

We have thoroughly investigated the issue on our end, and it seems that it could be an integration-related issue. The Data models in Builder are not included in visual views and are solely subject to bandwidth metering. As a result, these models should not trigger additional pixel tracking for visual views.

Please carefully review if any page sections inadvertently utilize visual components or if content queries are causing implicit visual views. It is important to ensure that all content queries are specifically for data models and are rendered correctly.

In order for us to provide further assistance, we kindly ask for more detailed insights into your data model integration.

Thank you.

Hello @nikola,

I hope this message finds you well. Just checking in to see if you’re still dealing with any problems related to pixel tracking and data model integration. If you are, please provide us with the integration code or a minimal reproducible case so that we can offer you further assistance.

Thank you.

1 Like

Hello @manish-sharma, let me introduce you to our use case with some updated context.

We are using the next.js app and on the search page (search.tsx) we are calling:

builder.getAll(‘search-settings’, options) - ‘search-settings’ is a data model
builder.getAll(‘content-page’, options) - ‘content-page’ is a page model and here we are using ‘prerender: false’ in order to return JSON and returning only a few fields in order to build search filters.

in layout.tsx that is the wrapper for this page we are using:
builder.get(‘navigation’) - ‘navigation’ is a data model
builder.get(‘footer’) - ‘footer’ is a data model
builder.get(‘utility-bar’) - ‘utility-bar’ is a data model

and when changing filters on that page we are changing query params and calling our API that is making a call:
builder.getAll(‘content-page’, options) - ‘content-page’ is a page model and here we are using ‘prerender: false’, here we are retrieving results.

Each query param change is calling tracking pixel with the page counter increased. Is that supposed to happen with our setup?

We are not using ‘BuilderComponent’ anywhere on those pages I say that because I think that it is responsible for increasing page views. We are using it on some other pages. Also all of those action are on server side portion of next.js app. We are using edge runtime because we are hosting our app on the Cloudflare Pages.

Additionally,

when we query a page we don’t have in builder.io and show a 404 page we get a tracking pixel called.

Initially, we are checking if a page model with urlPath is provided by builder.get; if not, we are rendering our own 404 page.

Again, that page uses a layout that is retrieving navigation, footer, utility-bar but they are all data models.

Why are we getting tracking pixels there? Are tracking pixels counting API calls? From the documentation, I can see that the visual view should only be tracked when a single Page contains content entries from the builder.io but what is the case if it does not return results like 404?

Hello @nikola,

Again, querying data models like navigation , footer , and utility bar should not trigger tracking pixels as they are not considered visual content models.

When querying a page model that results in a 404 (i.e., the page does not exist), Builder.io tracking pixels can still be triggered. This is primarily due to how the SDK, alongside the server-side logic, handles the requests and responses.

To prevent the tracking pixels from firing when rendering a 404 page, you can try and implement the following steps:

  1. Implement a check to disable tracking specifically when rendering a 404 page:
import { builder } from '@builder.io/sdk';

// Replace with your Public API Key
builder.init(YOUR_API_KEY);

export async function getPageContent(urlPath) {
  const content = await builder.get('page', {
    userAttributes: {
      urlPath: urlPath,
    },
    prerender: false,
  }).toPromise();

  if (!content) {
    builder.canTrack = false;  // Disable tracking for 404 pages
    return null;
  }
  
  return content;
}
  1. Modify Fetch Function : Use a custom function to fetch the builder content while ensuring tracking is disabled if the content does not exist:
async function fetchWithConditionalTracking(model, options) {
 builder.canTrack = false;  // Disable tracking
 const data = await builder.get(model, options);

 if (data) {
   builder.canTrack = true;  // Enable tracking if data exists
 }

 return data;
}

// Example usage in getStaticProps or similar function
export async function getStaticProps({ params }) {
 const pageContent = await fetchWithConditionalTracking('page', {
   userAttributes: {
     urlPath: '/' + (params?.page?.join('/') || ''),
   },
   prerender: false,
 });

 return {
   props: {
     page: pageContent ? pageContent : null,
   },
   revalidate: 5,
 };
}
  1. Handling in Layout and Query Changes : Ensure that any dynamic layout or query changes also respect this tracking behavior:
// Example API call handling with conditional tracking
builder.getAll('content-page', { ...options, prerender: false }).then(results => {
  if (!results.length) {
    builder.canTrack = false;  // Disable tracking if no results found
  }
  // Handle results
});

Let us know how the above suggestions work for you!

Thanks,

1 Like

Hello @manish-sharma, thanks for the response and suggestion.

I have put builder.canTrack = false after the SDK calls if I don’t receive results and I can still see the same kind of tracking requests to api2.amplitude.com with events that contain something like event_type: "[Amplitude] Page Viewed".

I went even further and put the same code after every builder.init I have in my codebase, but nothing happens, we have calls again.

The real question is if those calls are increasing page views or if we don’t need to care about that?

I ask that because in builder.io dashboard I don’t see any page views for my search page nor any 404 page I hint which is normal. I see only counts for the pages registered as a page model in builder.io. My concern was whether those numbers would increase in any way because of those calls to api2.amplitude.com, even if we are not rendering content from the page model.

Thanks


Hello @nikola,

The tracking calls you see to api2.amplitude.com do not affect the page view tracking in Builder.io and thus won’t impact your Builder.io dashboard statistics.

If you see requests to api2.amplitude.com it indicates custom Amplitude event tracking set in your implementation. These events are separate from the default tracking Builder.io conducts.

Builder analytics are captured by sending a request to https://cdn.builder.io/api/v1/track


To know more you can refer to the below links

Hope this helps!

Thanks,

1 Like