There are PPC management tools that already do this though and they do it with all your incoming traffic.
I would say that there are analytical tools that are offering such a feature for a long, long time. They are not free, but you can develop a tool that will log the 1st, 2nd to last external referrer. Real problem is with success allocation. Most people are just looking at last referrer, some are using first, some are allocation a portion to each one.
I'm seeing several paths which have multiple clicks on the same keyword.
Are you looking at bid keywords (broad of phrase matching), or searched keyword?