Restructured tracker.js to reduce duplication