Dynamics NAV and Google Analytics – Part 2/2

Now that we have our C#.NET add-in that we made in part 1. We can now make a codeunit wrapper and start tracking user actions.

The codeunit

This codeunit is very simple, we just need wrapper around the .NET add-in methods. If you made more methods in part 1 to track different things, then you are going to need a function in NAV for each one. Don’t forget to call Hit.postData()  at the end of each method that should send a hit. Since we want to use the hooks pattern for this add-in, write as much of the C/AL code as possible in this new codeunit. This way the impact on other objects is at a minimum. This makes upgrading and merging code much easier later on.


Tracking a hit

For each page you want to track add the codeunit as a global variable.


Next you will want to go through each action and add in the method calls. Notice here that each action only requires one line of code added in. The first parameter is our page name, in this case ‘Sales Orders’ and the second parameter is the action name. Since a lot of action names default to ‘ActionX’ I usually will use the caption name instead. This makes reports a lot easier to read, as you will know the actual name, instead of constantly referencing back to the development environment to see what ‘Action33’ is.  You could track more than just actions. For example, if you wanted to see how many times the description on the item card is updated you could add a similar line of code to the description  OnValidate() method.




Viewing the results on the Google Analytics dashboard we can see how many times an action was pressed, and on what page. For this chart our Event Category is the page name and the label is our action name. The value is how many times that action was pressed.  You can create and customize these charts to fit the data you are sending to Google. Hits won’t appear right away, it can take up to a few hours for hits to fully register.

Google Analytics output chart

There are many other things you could track with Google Analytics. User input is just one example.  You could also pass additional information with your hits such as user information. Talk with your business intelligence team to see what information you could track to get the best value out of using Google Analytics.


If you have any suggestions on what you would like to see Dynamics NAV integrated with, leave a comment or email myself at ryan.erb@me.com.



Leave a Comment