Append Tracking Template Automatically using Javascript

Below is the piece of code that can be used to append the tracking template automatically:

<script>
// Get all the URL values into a custom defined variable
var url = document.querySelectorAll("a");

// Use a loop to read all the URL values
for (var i = 0; i < url.length; i++) {
// Save all href attributes in a variable
var sample_variable [...]