Unable to capture clicks using PageAction

I’ve got the script below

window.addEventListener('DOMContentLoaded', (event) => {
document.querySelectorAll("a[href='example.com']").forEach(el => el.addEventListener('click',function (e) {
            newrelic.addPageAction('Doc');

        }))
    });

I am trying to capture count of hits whenever the user opens the document enclosed within anchor tag with href present but no ID property. The document opens in another window. Its not firing the click event or recording the count of click.

I used below NRQL

count(actionName) as Hits FROM PageAction SINCE 1 day ago WHERE appName =‘Gknowledge’ WHERE actionName=‘Doc’

Hey @Mohd.Salman2,

I suspect that what’s happening is that in opening up the new window you’re navigating away from the page where the event is occurring before the action can be harvested. If the user stays on the original page while the new document opens in a new window, does the click then get recorded as a PageAction?

Hi @hwilkalis

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

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?

Hi @sathiaseelan.kuppusa,

I recognized the script from your example as one I was just working on with one of my colleagues earlier in the day over on your post at How to find the number of clicks happened in a page?. Cheryl is responding to your questions over there so let’s keep the conversation about your questions in that thread so we’re not accidentally duplicating efforts.