Ignore parts of the url or dynamically rewrite/alias the url I am having a problem and have been wrecking my brain over it...

I feel I might ohh how did I not think of that moment once I find the solution...

Basically, what I need to do is:

For any url containing a string like "abcmytrack" show the page/view/drupal url that is before it in url and ignore the rest. So if I go to node/1/abcmytrack/some/other/stuff/abc then just show node/1, if I go to nodeone/alias/page/abcmytrack/some/other then again just show nodeone/alias, but keep abcmytrack/some/other in the url.

What am I trying to do:
there is some referral tracking that I am trying to implement in the form of. 

/some/drupal/url/[trackid]/some/other/track/ids/even
/any/drupal/url/[trackid]/any/even/number/of/arguments
/[trackid]/some/other/set/of/arguments

basically for any url with [trackid] which is a string. It should just ignore anything starting with [trackid] and load the path before it as if [trackid] was not there. 

The result is that they basically get converted to a cookie, but the site is behind varnish and akamai caching so on production the code does not run and cookie is not written.  Best option at the moment is to use JS to write a cookie, but problem is that adding /[trackid]/some/other/set/of/arguments to some of the site urls like aliased node paths, homepage, etc. breaks the pages. 

It might be possible to do it as url rewrites in .htaccess but this is a last resort.  I would like to see if there are other options I am not considering. 

I have attempted to do use hook_url_inbound_alter but it seems to do redirects and I loose the string from the url or otherwise it url encodes the string. 

I have been wrecking my brain on this and cannot make this work. Granted I have some interesting requirements but it is one of those things that should be straightforward but it is not.
Subpathauto might do what you need even if it wasn't written for that exact use case. https://www.drupal.org/project/subpathauto

Subpathauto was written to handle the case where those extra arguments at the end of the string are meaningful and the first portion of the string is an alias. For that to function it must use hook_url_inbound_alter (you were on the right track!) to look up the first section of the string.

Even if this module isn't an exact fit the code within it is a good starting point.