You can add Google Analytics tracking to an MDriven Turnkey application by placing the supplied integration files in the model's AssetsTK folder and setting your Google Analytics tracking account in its Angular configuration.
What this integration does
Google Analytics tracks usage of your Turnkey web application. This is different from Google authentication: analytics records site usage, while external login lets users sign in with a Google account. For Google sign-in configuration, see Documentation:External login services in MDriven Turnkey.
Before you start
You need:
- An MDriven Turnkey application and access to its model in MDriven Designer.
- A Google Analytics tracking code for the account that should receive the tracking data.
- The supplied attachment: File:Google analytics for Turnkey app.zip.
The supplied files provide the Angular analytics integration used by the configuration shown below.
Add the integration files
- Download File:Google analytics for Turnkey app.zip.
- Extract the archive.
- In MDriven Designer, open the model for the Turnkey application.
- Add the extracted files to the model's AssetsTK folder.
- Save the model.
- Deploy or update the Turnkey application using your normal deployment process.
For Turnkey deployment guidance, see HowTos:Install MDriven Server and Turnkey on Microsoft Azure and HowTos:Troubleshoot Turnkey Deployment.
Configure the Google Analytics account
Add the following Angular configuration. Replace UU-XXXXXXX-X with your own Google Analytics tracking code.
angular.module(MDrivenAngularAppModule).config(['AnalyticsProvider', function (AnalyticsProvider) {
// Add configuration code as desired
AnalyticsProvider.setAccount('UU-XXXXXXX-X'); // Replace with your tracking code
}]).run(['Analytics', function(Analytics) { }]);
The configuration does two things:
| Code | Purpose |
|---|---|
AnalyticsProvider.setAccount('...')
|
Sets the Google Analytics account that receives tracking data. For example, replace UU-XXXXXXX-X with the tracking code assigned to your application.
|
.run(['Analytics', function(Analytics) { }])
|
Loads the Analytics service when the Angular application starts.
|
Important distinction: analytics versus Google login
Do not enter a Google Analytics tracking code in the Google OAuth client ID or client secret fields used for external login. Those values configure different Google services.
| Requirement | Configure it here |
|---|---|
| Track use of the Turnkey application with Google Analytics | Add the supplied integration files to AssetsTK and set the account in the Angular configuration on this page. |
| Let users sign in with Google accounts | Documentation:External login services in MDriven Turnkey |
Related library
The integration configuration is based on angular-google-analytics. Review that project's documentation when you need configuration options beyond setting the account.
