{"id":22127261,"url":"https://github.com/bytexdigital/bytexdigital.blazor.components.googleanalytics","last_synced_at":"2026-04-28T01:32:13.706Z","repository":{"id":103210959,"uuid":"585933225","full_name":"BytexDigital/BytexDigital.Blazor.Components.GoogleAnalytics","owner":"BytexDigital","description":"Components for adding (GDPR compliant) Google Analytics","archived":false,"fork":false,"pushed_at":"2023-05-08T21:53:09.000Z","size":26,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-03-04T09:39:01.363Z","etag":null,"topics":["blazor","blazor-gdpr","blazor-google-analytics","blazor-gtag","blazor-ui","blazor-ui-components","blazor-ui-library","blazor-wasm","blazor-webassembly","gdpr","google-analytics"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/BytexDigital.Blazor.Components.GoogleAnalytics","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BytexDigital.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-06T13:38:31.000Z","updated_at":"2023-06-03T23:41:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"b8771665-ac78-4766-b996-76f0e5fbb0bf","html_url":"https://github.com/BytexDigital/BytexDigital.Blazor.Components.GoogleAnalytics","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BytexDigital%2FBytexDigital.Blazor.Components.GoogleAnalytics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BytexDigital%2FBytexDigital.Blazor.Components.GoogleAnalytics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BytexDigital%2FBytexDigital.Blazor.Components.GoogleAnalytics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BytexDigital%2FBytexDigital.Blazor.Components.GoogleAnalytics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BytexDigital","download_url":"https://codeload.github.com/BytexDigital/BytexDigital.Blazor.Components.GoogleAnalytics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245233320,"owners_count":20581781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blazor","blazor-gdpr","blazor-google-analytics","blazor-gtag","blazor-ui","blazor-ui-components","blazor-ui-library","blazor-wasm","blazor-webassembly","gdpr","google-analytics"],"created_at":"2024-12-01T17:17:36.316Z","updated_at":"2026-04-28T01:32:13.682Z","avatar_url":"https://github.com/BytexDigital.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GoogleAnalytics\nThis library adds a simple way to integrate Google Analytics in your Blazor WASM/Serverside app. Make your integration of Google Analytics GDPR compliant by using our [BytexDigital.Blazor.Components.CookieConsent](https://github.com/BytexDigital/BytexDigital.Blazor.Components.CookieConsent) library.\n\n## How to install\n```ps1\nInstall-Package BytexDigital.Blazor.Components.GoogleAnalytics\n```\n\n\u003cbr /\u003e\n\n### Requirements\n.NET \u003e= 5.0\n\n\u003cbr /\u003e\n\n### Configure in your project\n\n#### 1. Configure your App.razor\nBeneath\n\n```csharp\n\u003c/Router\u003e\n```\n\nadd\n\n```csharp\n\u003cBytexDigital.Blazor.Components.GoogleAnalytics.NavigationAnalyticsTracker /\u003e\n```\n\n#### 2. Configure your Program.cs\nAdd the following call with your desired settings.\n\n```csharp\nbuilder.Services.AddGoogleAnalytics(options =\u003e\n{\n    options.TrackingId = \"G-YOUR_ID\";\n    options.AutomaticallyInitialize = true;\n    options.AutomaticallyEnableTracking = true;\n});\n```\n\n#### 3. Include necessary JavaScript\nInside your index.html/_Host.cshtml, add the required JS include where you see fit.\n```html\n\u003cscript src=\"_content/BytexDigital.Blazor.Components.GoogleAnalytics/Analytics.js\"\u003e\u003c/script\u003e\n```\n\n## Usage together with [BytexDigital.Blazor.Components.CookieConsent](https://github.com/BytexDigital/BytexDigital.Blazor.Components.CookieConsent)\nUsing [BytexDigital.Blazor.Components.CookieConsent](https://github.com/BytexDigital/BytexDigital.Blazor.Components.CookieConsent), you can easily make the usage of Google Analytics in your app GDPR compliant by delaying initialization of Google Analytics until user consent for tracking has been given.\n\nTo enable this scenario, you should first disable automatic initialization:\n\n```csharp\nbuilder.Services.AddGoogleAnalytics(options =\u003e\n{\n    options.TrackingId = \"G-YOUR_ID\";\n    options.AutomaticallyInitialize = false; // Disabled\n    options.AutomaticallyEnableTracking = true;\n});\n```\n\nAfter installing the CookieConsent library and following it's installation instructions, you can add a \"Google Analytics\" category, which the user has to give consent to for Google Analytics to load and start tracking user behaviour on the website.\n\nThe category could be added as follows with the name `analytics`:\n\n```csharp\nbuilder.Services.AddCookieConsent(o =\u003e\n{\n    // .. Other non related configuration omitted\n    \n    // \n    o.Categories.Add(new CookieCategory\n    {\n        Identifier = \"analytics\", // Unique name for this category\n        IsPreselected = false, // In a GDPR compliant scenario, non-essential categories may not be preselected, hence, this has to be false.\n    \n        TitleText = new Dictionary\u003cstring, string\u003e\n        {\n            [\"en\"] = \"Analytics\"\n        },\n        DescriptionText = new Dictionary\u003cstring, string\u003e\n        {\n            [\"en\"] = \"Allows the integration and usage of Google Analytics to track user behavior on our website.\"\n        },\n\n        Services = new List\u003cCookieCategoryService\u003e\n        {\n            new()\n            {\n                Identifier = \"analytics\",\n                PolicyUrl = \"https://policies.google.com/privacy\",\n                TitleText = new Dictionary\u003cstring, string\u003e\n                {\n                    [\"en\"] = \"Google Analytics\"\n                },\n                ShowPolicyText = new Dictionary\u003cstring, string\u003e\n                {\n                    [\"en\"] = \"Show policy\"\n                }\n            }\n        }\n    });\n});\n```\n\nInside your App.razor, you can now listen for the CookieConsent library to broadcast the event that the user has changed his cookie preferences and use the given preferences to determine whether the GoogleAnalytics library can now initialize and begin tracking, for example as follows:\n\n```cs\n// Prior RazorHMTL content of your App.razor\n\n@code {\n\n    [Inject]\n    public GoogleAnalyticsService GoogleAnalyticsService { get; set; }\n\n    [Inject]\n    public CookieConsentService CookieConsentService { get; set; }\n\n    protected override void OnInitialized()\n    {\n        // Subscribe to the CookiePreferencesChanged event so we can react to given consent.\n        CookieConsentService.CookiePreferencesChanged += async (sender, preferences) =\u003e await OnPreferencesChangedAsync();\n    }\n\n    protected async Task OnPreferencesChangedAsync()\n    {\n        // Fetch the now active cookie preferences.\n        var preferences = await CookieConsentService.GetPreferencesAsync();\n\n        if (preferences.AllowedServices.Contains(\"analytics\"))\n        {\n            // If analytics are allowed by user consent, initialize GoogleAnalytics.\n            await GoogleAnalyticsService.InitializeAsync(default);\n        }\n    }\n\n}\n```\n\n# Changelog\n\n### 1.0.0\n\n\u003cdetails\u003e\n  \u003csummary\u003eClick to expand!\u003c/summary\u003e\n\n   \u003cbr /\u003e \n\n- Initial release\n\u003c/details\u003e\n\n# Licensed content\n\nThis library contains code from the following sources.\n```cs\n/*\n\nhttps://github.com/isc30/blazor-analytics\nMIT License\nCopyright (c) 2019 Ivan Sanz Carasa\n\n*/\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytexdigital%2Fbytexdigital.blazor.components.googleanalytics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbytexdigital%2Fbytexdigital.blazor.components.googleanalytics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbytexdigital%2Fbytexdigital.blazor.components.googleanalytics/lists"}