Amazon Package Tracking Greasemonkey Script

Amazon, eBay, and other online retailers are displaying package tracking information on their website for your orders, which is convenient, but how up-to-date the information is? Based on my research, there is always delay that up to hours or even days. Why? Because they are relying on the carrier’s infrastructure to provide the tracking data:

  • Push. This requires carrier to publish event to Amazon, and then Amazon can aggregate the data for display. Usually carriers do not have the technology that publishes the data at real-time, they are not tech companies after all.
  • Pull. This requires carrier to have a scalable infrastructure that can take all Amazon’s requests. It is not just about request volume, but also the speed – Amazon does not want customers to wait for seconds until the information shows up.

Either way, the delay is inevitable. As a customer, I always go to the carrier’s website to acquire the latest tracking information, and this is what I do:

  1. Highlight the tracking number.
  2. Right click and select “Search Google for …”.
  3. Select the right carrier suggested by Google.
  4. Land on the carrier’s website.

To make it easier for me, I should add a hyperlink for the tracking number so that it redirects me to the carrier’s website with one-click. Why not call carrier’s API to retrieve the data directly? Well, it requires registration with all the carriers and I am being lazy…

Okay, in order to achieve that, I need to write a Greasemonkey script.

Step 1: Install Tempormonkey Chrome add-on.

Step 2: Write some code!

// ==UserScript==
// @name Amazon Package Tracking Script
// @namespace
// @version 0.1
// @description Add link to tracking number that directs to the carrier's tracking website
// @author me
// @match*
// @require
// ==/UserScript==

(function() {
'use strict';
// Get the DOM element
var ele = $("div .ship-track-grid-subtext");
if (!ele) return;
var text = ele[0].innerHTML.trim();

// Get carrier's name
var carrierName = getCarrierName(text);
console.log("carrier name: " + carrierName);
// Get tracking number
var trackingNumber = getTrackingNumber(text);
console.log("tracking number: " + trackingNumber);

// Get tracking website's URL
var url = getTrackingWebsiteURL(carrierName, trackingNumber);
if (url) {
  ele.wrap("<a target='_blank' href='" + url + "'></a>");

function getCarrierName(text) {
  var index1 = text.indexOf(":") + 1;
  var index2 = text.indexOf(",");
  var carrier = text.substring(index1, index2).trim();
  switch(carrier) {
    case "UPS Mail Innovations":
      return "USPS";
      return carrier;

function getTrackingNumber(text) {
  var index1 = text.lastIndexOf(":") + 1;
  var tracking = text.substr(index1).trim();
  return tracking;

function getTrackingWebsiteURL(carrierName, trackingNumber) {
  switch(carrierName) {
    case "USPS":
      return "" + trackingNumber;
    case "ONTRAC":
      return "" + trackingNumber;
    case "UPS":
      return "" + trackingNumber;
      return "";

That’s it!

Download the script from GitHub here.