Events firing multiple times

Hi,
I am trying to create a funnel and I have 4web pages, I am firing PageView events in each page.
After clicking button in each page it goes to the next page(1 -> 2 -> 3 -> 4)
The problem I am facing is PageView event is being fired 2 times for secondpage, 3times for 3rd page, 4 times for 4th page

Here is my Secondpage.html code:

function myFunction() {
window.snowplow(‘trackPageView’);
window.location = 'http://0.0.0.0:8000/thirdpage.html;
}

<form action=/onsubmit="myFunction()">
  <br>
  <input type="button" value="Viewed" onclick='myFunction();'>

Hi @Mounika_M
This is likely firing multiple times as you are calling the function in both the button onclick and on the form submit action. Also, you might be calling trackPageView when you load the Snowplow Tracker, as we often suggest in our code snippets to place a page view event there too.

Generally, when we want to track page views we will put the trackPageView call in the same JavaScript tag as when we initialise the tracker. This way we can be sure that on each new HTML page that loads, the trackPageView event is only called once per page load.

The initialisation and tracking code would look something like this:

        <script>
            window.snowplow('newTracker', 'sp', 'my-collector-url.com', {
                appId: 'test-123',
                contexts: {
                    webPage: true,
                    performanceTiming: true
                }
            });
            window.snowplow('trackPageView');
        </script>

Ideally you would want to send a different type of event when a user submits a form. If you are looking at form tracking, then you might want to try and enable form tracking that is built into the Snowplow JavaScript Tracker (See here).

1 Like