Count DTMF events during call and save it as an AGI variable

I am using Asterisk version 11 and need to keep track of the number of dtmf events during a call and save this number to an AGI variable.

I have experience programming in C++, C#, Java, Javascript, and PHP but am new to asterisk. I bought the book “Asterisk: The Definitive Guide (4th Edition)” and have read about 75% of it and been able to set up an asterisk server able to make and receive calls.

The company I am doing this for is currently on version 1.6 and they are trying to move to 11. The solution they have in 1.6 uses a custom written app and function as well as modifying channel.h and channel.c files. Would that be necessary in 11 or is there a better way?