Measuring visitor behavior is very simple in Magento in combination with Google Analytics. You will also receive a tracking code when you create your Google Analytics account. Often this tracking code starts with UA, for example UA-123456-1. Copy the whole code and then log in to your Magento admin dashboard.
1) Click on 'Stores' and then click on 'Configuration'
2) Scroll to the 'Sales' tab (the 7th tab) and click on Google API.
3) Then enable Google Analytics and enter your tracking code in the 'Account Number' field.
Note: remember to 'Save' your changes and empty the Magento cache.