The secret is in appropriately defining the word "productivity." Many people say that they want to "measure productivity," but have never thought about what productivity actually is. How can you measure something if you haven't even defined it?
The key to understanding what productivity is, is realizing that it has to do with products. A person who is productive is a person who regularly and efficiently produces products.
The way to measure the productivity of a developer is to measure the product that they produce.
That statement alone probably isn't enough to resolve the problem, though. So let me give you some examples of things you wouldn't measure, and then some things you would, to give you a general idea.