Tracking Events in a Javascript File

BACKGROUND: I have a large number of events that are triggered with Javascript, rather than HTML link elements. These triggers lie in a file devoted entirely to Javascript and is tagged with the extension .js.

Since the Javascript Tracker is written in Javascript I am prone to place the script at the bottom of the file and capture the proxy links (jQuery .click() functions) contained therein as events.

QUESTION(S): Does Matomo care about the nature of the file from which it gathers data? Does the extension or document type matter? Will matomo track events in such a setting?


If I understand you correctly, you are calling additional JavaScript functions into your document via a referenced js file.

The extension and method of intergration (external or inline) are not important to the tracking. What is important is the order and language, so ensure if you want any data to be pushed on pageview to be added to the browser DOM before the Matomo tracker (tag) is referenced and also follow the documention :slight_smile: - you have Ilkley already found:

For event tracking you can place those anywhere, referencing an asynchronous js file as you are is a good idea though. Controlling the tag and tracker is made every more easier now with the Matomo tag manager!

Thank you, Louis, you have confirmed my belief, and I will proceed as intended.


Follow-up: Implemented. Yes, it works. Thank you, once again.


1 Like