Content in English JavaScript/PHP

Ultimate guide – how to use custom JavaScript in Microsoft Sharepoint Online

Recently I have tried to implement Google Tag Manager in MS Sharepoint Online. For the usual website this would be the matter of minutes. However, in MS Sharepoint Online, it is kind of bigger challenge.

First and most important – there is no easy way in new Sharepoint Experience interface

New Sharepoint experience really have no option, how to add custom JavaScript. However, in December 2016 Microsoft launched Sharepoint Framework for first adoptees. Thus, we can expect final solution for all corporate customisation in 2017. Lately (end of January 2017), there has been several updates regarding customization. You may read:

Back-up your Sharepoint Online

Any method described can be a reason for Sharepoint error. The good thing is, your Sharepoint site collections are back-up regularly and you have 14 days to ask for a back-up. Yes, you must ask via authorized request in Office 365 admin. There are some other back-up option but there are from non-MS vendors.

Method #1 – Use iframe webpart

You may create a web-part as an iframe to your script. Firstly you must allow your source site as allowed iframe location in settings (by default only few sites as YouTube are approved). Read more: Step by step guide how to embed script as webpart

Method #2 – Set-up user custom action

You may set up a custom action that will add your JavaScript to master pages without the need to edit them.

Method #3 – Use extension

There is one extension that can help you. I have not tested it. You can get it on MS Store .

Method #4 – Not recommended – Tweak Master Pages

Yes, you can. If you download software Microsoft Sharepoint Designer, you may easily connect to your Sharepoint instance and edit ASPX source code of all master pages. However, this method is really future-fail. Your Sharepoint can start behave unexpectedly because of new updates. Also 2 times from 3 tries, after master page tweak I got an error that had nothing in common with the change I have just made. I would really not recommend this on MS Sharepoint Online (I am not experienced ASP programmer). You may have problems to connect to your instance. Then you must download SharePoint Online Management Shell and allow that connection. If you edit master pages, always back-up, always preview your changes and be sure that your script is HTTPS not to broke your SSL certificate.


To summarize it, there has been no easy way yet. The new Sharepoint Framework will be the solution (available sometimes in 2017). I would also love to thank two Czech companies who shared some valuable information with me that helped me create this article – RSM Infinity (complex IT services) and Multima (specialists for software development and collaboration). Please feel free to comment bellow or share this article.

Mohlo by se vám také líbit
When will my Twitter account become eligible for advertising?
JavaScript v GTM – Measure Camp Brno 2017