How to find the number of clicks happened in a page?

Is there any way to find out the total number of clicks on a web page in the ‘Browser’ module?

We would want to find out the number of clicks made by the users. If there are more sections/grids available on a single page, how do we filter the sections/grids based on the total number of clicks?

Please advise

Hello @sathiaseelan.kuppusa!

Thanks for the great question! I wanted to share a similar post from the community with examples here if that helps with your use case.

Also, I’m linking to our documentation here on using the Browser API functionality to capture PageAction data that you can query for number of clicks via NRQL and Query Builder.

I hope that helps get you started. Let us know if there’s anything else you want to know about.

Hello @cfrankenfield

Thanks for the heads up!

Even we tried this way to capture the number of clicks using addPageAction, but it didn’t turn up

I have added a button on the web page and also added the below script in the head section and ran the below NRQL in Insights, but the result was shown as 0 PageActions.

document.getElementById('click-me').addEventListener('click',function (e) {
    newrelic.addPageAction('testMe');
})

Here is the NRQL

SELECT count(*) FROM PageAction WHERE actionName=‘testMe’ SINCE 1 hour ago

It is not recording the click events. So how do we get the pageActions results and find out the number of clicks made by the users against every button/section/grid on a page? Are we missing anything here or do I need to do any additional configuration to resolve this?

Please assist

Hello @sathiaseelan.kuppusa !

It sounds like maybe the API call you’re using is called before the element has been created, a button or whatever element is loading later in the document in the body tag. If you test moving your script to run after your button or similar element is created and available, you should be able to see PageAction events.

Also, if you check in the Network tab of your browser console, the ins endpoint or https://bam.nr-data.net/ins/1 call to our collector is for the PageAction so you should see that if it’s successfully being captured.

To note, this additional API call will capture clicks only on those targeted elements and not necessarily total number of clicks on a page by a user, though please feel free to clarify your use case. Thank you!

Hi @cfrankenfield

Thanks for the response. I moved my script after my button is created and it is working fine. I am able to see the number of clicks using NRQL query in insights.

Can I get the output in any of the following formats using NRQL Query?

  1. Bar Chart
  2. Pie Chart
  3. Line Graph

Or any user friendly chart. Please assist

That’s great to hear! To answer your question about NRQL query export formats, I’m including some documentation below:

https://docs.newrelic.com/docs/query-your-data/nrql-new-relic-query-language/get-started/introduction-nrql-new-relics-query-language

https://docs.newrelic.com/docs/query-your-data/explore-query-data/use-charts/use-your-charts#change-appearance

https://docs.newrelic.com/docs/query-your-data/explore-query-data/data-explorer/introduction-data-explorer

https://docs.newrelic.com/docs/insights/use-insights-ui/export-data/export-insights-data-csv-file

I hope these resources include what you are looking for but if you need anything else, please let us know!

1 Like

Hi!

Now that I got the total number of clicks happened in a page, is there a way to retrieve number of clicks triggered for each actionable item (ex: links, buttons) in an html page?

Hello @sathiaseelan.kuppusa!

The API call you are using will capture clicks only on those targeted elements and not necessarily total number of clicks on a page by a user.

The examples listed in the documentation here detail how to use this API call on a clickable link (also with JQuery) and a form input example. Essentially, you should be able to target links, buttons, etc., by using something similar.

Please let me know if you need anything else!

2 Likes