title: how to capture user activity using javascript or angular
body: <p>i have an assignment to create a chatbot plugin using angular and the app can be imported to other website framework.</p>
  <p>there is an objective that i need to get the user activity on the page (not on the chatbot plugin), something like if the user click/hover any specific tag such as <code>a</code> tag or <code>img</code> tag, that tag will send to the server</p>
  <p>imagine website owner have this code in their site</p>
  <pre><code>&lt;a class=&quot;view-products&quot; target=&quot;_self&quot; href=&quot;https://alfaprav.com/shop/&quot;&gt;&lt;span&gt;Shop More&lt;/span&gt;&lt;/a&gt;
  </code></pre>
  <p>when the user click/hover that tag it will send to the server as a string</p>
  <p>i've followed several stackoverflow solutions but didn't suits my need. this is the closest solution  <a href="http://jsfiddle.net/94dd343y/" rel="nofollow noreferrer">http://jsfiddle.net/94dd343y/</a> but i dont know how to implement that to my app, is it needs to be inserted inside my angular app or i need new <code>.js</code> file just for that. any thought would be very helpful</p>
  <p>EDIT</p>
  <p>here's how this plugin will look like</p>
  <p><a href="https://i.stack.imgur.com/kavVz.png" rel="nofollow noreferrer">enter image description here</a></p>
  <p>EDIT 2</p>
  <p>Thanks to <a href="https://stackoverflow.com/users/10125418/julian-liu">Julian</a> now i have this code</p>
  <pre><code>  ngOnInit() {
      this.document.body.addEventListener('click', (e) =&gt; {
        // console.log(e.target);
        console.log(e.target);
        
      }, false);
      }
  </code></pre>
  <p>and i got the tags, but there's problem when user click body it shows all tags from  to  how to prevent that?</p>
  <p>EDIT 3</p>
  <p>After reading answer from <a href="https://stackoverflow.com/users/915693/pooya-estakhri">pooya</a> i change it to this</p>
  <pre><code>const elements = this.element.nativeElement.querySelectorAll('div');
  elements.forEach(element =&gt; {
    element.addEventListener('click', (e =&gt;{
      console.log(e.target);
    }))
  })
  </code></pre>