Svelte Google Analytics screenshot

Svelte Google Analytics

Author Avatar Theme by Beyonk group
Updated: 23 May 2022
76 Stars

Google Analytics component for Svelte

Overview

The Svelte Google Analytics package is a tool that supports the integration of Google Analytics v4 into Svelte v3 projects. It allows users to track and analyze various events and user properties through Google Analytics. With the package, users can enable/disable analytics, track page views and custom events, send events to different properties, set user properties, and link user sessions together by setting a user ID. Additionally, users have the option to add a Google Analytics ID after initialization by calling the setConfig function.

Features

  • Supports Google Analytics v4: The package allows users to integrate Google Analytics v4 into their Svelte v3 projects.
  • Enable/Disable Analytics: Users can enable or disable analytics using the enabled property. This feature is useful for complying with GDPR regulations.
  • Track Page Views: The package provides automatic page tracking functionality with Google Analytics v4.
  • Event Tracking: Users can implement and track various events specified in the documentation.
  • Custom Events: Users can track custom events using the addEvent function.
  • Multiple Properties: Users can send events to different Google Analytics properties by specifying the property ID.
  • Set User Properties: Users can split users into different segments and set properties such as language preference or geographic location.
  • Set User ID: Users can identify users inside Google Analytics and link their sessions together.
  • Set Config: Users can add a Google Analytics ID after initialization by calling the setConfig function.

Installation

To install the Svelte Google Analytics package, follow these steps:

  1. Open your terminal and navigate to the root directory of your Svelte v3 project.

  2. Run the following command to install the package using npm:

    npm install svelte-google-analytics
    
  3. Once the installation is complete, you can import and use the package in your Svelte components.

    import { GoogleAnalytics, init, addEvent, send_to } from "svelte-google-analytics";
    
    // Your component code
    

Summary

The Svelte Google Analytics package provides convenient integration of Google Analytics v4 into Svelte v3 projects. It offers a range of features, including enabling/disabling analytics, tracking page views and custom events, sending events to different properties, setting user properties, linking user sessions, and adding a Google Analytics ID after initialization. By using this package, Svelte developers can easily implement and manage Google Analytics tracking within their applications.