1.2.0 • Published 4 months ago

@microfox/google-analytics v1.2.0

Weekly downloads
-
License
-
Repository
github
Last release
4 months ago

Google Analytics SDK

A TypeScript SDK for interacting with the Google Analytics API.

Installation

npm install @microfox/google-analytics

Environment Variables

The following environment variables are used by this SDK:

  • GOOGLE_ANALYTICS_CLIENT_ID: The client ID for your Google Cloud project. (Required)
  • GOOGLE_ANALYTICS_CLIENT_SECRET: The client secret for your Google Cloud project. (Required)
  • GOOGLE_ANALYTICS_REDIRECT_URI: The redirect URI for your OAuth 2.0 credentials. (Required)
  • GOOGLE_ANALYTICS_ACCESS_TOKEN: The access token for authenticating with the Google Analytics Data API. (Required)

Additional Information

To use this Google Analytics SDK, you need to set up a Google Cloud project and enable the Google Analytics Data API.

Visit the Google Cloud Console (https://console.cloud.google.com/) to create a new project or select an existing one.

Enable the Google Analytics Data API for your project in the API Library.

Create OAuth 2.0 credentials (client ID and client secret) in the Credentials section.

Set up your OAuth consent screen with the necessary scopes ('https://www.googleapis.com/auth/analytics.readonly' for read-only access or 'https://www.googleapis.com/auth/analytics' for full access).

Store your client ID, client secret, and redirect URI securely. Never commit these to version control.

Set up environment variables for your credentials:

  • GOOGLE_ANALYTICS_CLIENT_ID

  • GOOGLE_ANALYTICS_CLIENT_SECRET

  • GOOGLE_ANALYTICS_REDIRECT_URI

  • GOOGLE_ANALYTICS_ACCESS_TOKEN

Obtain an access token using the OAuth 2.0 flow. You can use the @microfox/google-oauth package to handle the OAuth process.

When initializing the SDK, use the createGoogleAnalyticsSDK function and pass in the required configuration.

Be aware of Google Analytics API quotas and limits. Default quota is 10,000 requests per day per project.

For high-volume applications, consider implementing exponential backoff and retry logic for API requests.

Always validate and sanitize user inputs before passing them to the API to prevent injection attacks.

Keep your access token secure and refresh it when necessary using the refreshAccessToken method.

Consult the official Google Analytics Data API documentation for the most up-to-date information on endpoints, parameters, and best practices.

API Reference

For detailed documentation on the constructor and all available functions, see:

1.2.0

4 months ago

1.1.1

5 months ago

1.1.0

6 months ago

1.0.1

6 months ago