Default Pageview event and properties set with zaraz.set()

Hello, I’m using zaraz.set("brand", "my-brand-name" , {scope: 'page'} ); to add contexte to events.

It’s working well. However, sometimes, the brand property is missing from the Pageview event. I guess the Pageview event is triggered before I set the brand.

My question is, how can I make sure the brand propriety is in the Pageview event?

My page structure is as follows:

<head>
    <script src="zaraz-script.js" referrerpolicy="origin"></script>
</head>
<body>
    ...
    <script src="where-i-set-zaraz-properties.js" defer></script>
</body>

Thank you

If you move

    <script src="where-i-set-zaraz-properties.js" defer></script>

to be before

    <script src="zaraz-script.js" referrerpolicy="origin"></script>

and remove the defer attribute, it will for sure happen before Zaraz.

1 Like

Of course, but Zaraz wouldn’t be initialized at that point. Moreover, I need some information from the DOM, and I would have to wait for the DOMContentLoaded event if the script is in the head.

If you guys have other options, I’ll be glad to hear. Otherwise, I will try to use an inline script right after the <body> tag.

Yes, that should work. Any zaraz.set calls you make inside your HTML, that aren’t async or defered, would be picked up by the pageview. I don’t know what where-i-set-zaraz-properties.js does or how it works, but basically if you have somewhere in your <body> a `, it is guaranteed to be sent together with the pageview.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.