Features
Google Analytics Integration
Your application supports Google Analytics for tracking user activity and generating insights. Follow the steps below to set it up for development and production environments.
Setup Instructions
1. Create a Google Analytics Account
- Go to the Google Analytics website.
- Sign in with your Google account or create a new one.
- Click on Admin in the sidebar.
- Under the Account column, click Create Account.
- Fill in your account name and configure the data-sharing settings according to your preference.
- Under the Property column, click Create Property:
- Name your property.
- Select your reporting time zone and currency.
- Choose GA4 (Google Analytics 4) as the property type.
2. Obtain Your Tracking ID
- After creating the property, click Web in the property setup options.
- Enter your website URL and name.
- Click Create Stream.
- Copy the Measurement ID (e.g.,
G-XXXXXXXXXX). This is your tracking ID.
3. Integrate Google Analytics with Your Angular App
3.1. Add Google Analytics in Your App
- Open
main.tsfile in backend/src folder. - Add the Google Analytics module and tracking ID as shown below:
- Replace
YOUR_TRACKING_IDwith the Measurement ID obtained earlier.
3.2. Add Automatic Page View Tracking (Optional)
To track page views automatically, ensure your app uses Angular Router. The ngx-google-analytics module will handle routing events automatically.
3.3. Track Events (Optional)
To track custom events, you can use the NgxGoogleAnalyticsService:
Notes
- Ensure you publish your app's changes to reflect the integration.
- In production, configure any required privacy policies or cookie consent mechanisms for compliance.
Ready to Deploy?
You’re all set! Google Analytics will now start tracking your application’s activity. Refer to your Google Analytics dashboard for real-time and detailed insights.