How to Inject Google Analytics Code in SharePoint Online?

In SharePoint online, It is not recommended to change Master page to do the functionality of google analytics code.  The only option is to create custom action and do the script injection. Here is one such example is given  below.

CustomActionCollection collUserCustomAction = context.Site.UserCustomActions;
CustomAction userCustomAction = collUserCustomAction.Add();
CustomAction.Location = “ScriptLink”;
CustomAction.Sequence = 1;
CustomAction.ScriptSrc = “http://mysite/SiteAssets/ga.js”;
CustomAction.Title = “Google analytics Tracking “;
CustomAction.Description = “Google analytics Tracking in SharePointOnline”;

Happy SharePointing 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *