Send pageviews programmatically

Hello,

I have a similar issue to the following task:

I am setting up GA 4 and trying to setup a pageviews event to fire upon every navigation. I have turned off the default Pageview event from the Google Analytics 4 action and disabled the Single Page Application support from zaraz settings.

I am firing the pageview event using zaraz.track in the following way:

zaraz.track('page_view', {
    page_location: location,
    page_title: title,
});

The event fires successfully upon every navigation. The problem is the location and title data are not passed correctly in the event’s data.
Is my eventProperties’ object structure wrong? page_location and page_title are not the correct keys to target in order to pass the appropriate data?

Thanks in advance!

Just figured it out. Works fine. Thanks.

See FAQ · Cloudflare Zaraz docs

1 Like

@yoav_zaraz I’m adding zaraz.spaPageview() to trigger a page view in SPA manually. How do I avoid the initial automatic Zaraz Pageview trigger when the page loads? I want to avoid it because the dynamic page title was not yet set, and the pageview is duplicated when I call zaraz.spaPageview() with the correct title.

@giannis.alexiou, what did you end up doing?

@nikita5
You should deactivate the following option from Zaraz settings:

Then you have 2 options:

1 - use zaraz.spaPageview() as you mentioned
or
2 - use a zaraz.track function in the following way, passing the values programmatically:

zaraz.track('page_view', {
 page_location: url,
 page_title: title,
});

Yes, I have deactivated SPA support in settings, but Zaraz still triggers the initial pageview event on load. :thinking: