Forum Discussion

Usman555's avatar
Usman555
Copper Contributor
Sep 13, 2024

Adding google analytics to modern sharepoint site using SPFX Extension

hi,

We have a requirement to add Google Analytics to Sharepoint Online modern site - not to Site Collection

I followed below tutorial, but when i build it, i get the following error on  eval(` line of code.

https://sharepoint.handsontek.net/2017/12/21/how-to-add-google-analytics-to-the-modern-sharepoint/

 

eval(`
			window.dataLayer = window.dataLayer || [];
			function gtag(){dataLayer.push(arguments);}
			gtag('js', new Date());    
			gtag('config',  '${trackingID}');
		`);

 

Warning-lint - src/extensions/googleanalytics/GoogleanalyticsApplicationCustomizer.ts(51,7): error no-eval: eval can be harmful. 

Can any one recommend, how to either fix the above error, or some other way, to incorporate GA4 to Sharepoint site please?
Thank you

  • I would recommend you using Microsoft Clarity instead and incorporating Analytics to that!

    Also, GA and Clarity is not compliant with GDPR etc! So if you plan to use it in a company that's in the EU, it's not recommended

Resources