In the New Google docs editor, the Google Analytics built-in tracking and the insertion of custom HTML code were removed but they could be extended through add-ons and Google Apps Script.
Some methods and triggers are only available in bound scripts. You could use Google Scripts, the editor to hold stand-alone scripts, to create web apps and to hold code libraries that you could call from bound scripts.
References
#References Extend Google Docs, Sheets, and Forms with Apps Script