Tracking Events in a Javascript File


(Roddy A. Stegemann) #1

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?

Roddy


(Louis) #2

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:

https://matomo.org/docs/event-tracking/#tracking-events

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!

https://matomo.org/blog/2018/06/free-open-source-matomo-tag-manager-now-available-as-a-beta/


(Roddy A. Stegemann) #3

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

Roddy


(Roddy A. Stegemann) #4

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

Roddy