Forum Discussion
SharePoint Online Usage Statistics with JavaScript Injection Add-in
Steve
I can finally report some success. To make this easier I created two functions, one based on John's example and one I put together by looking at the link you gave and seeing if there is another way to write it. my second function works and gives no errors in the console. The PS works like a charm and simply replaces my customSciptAction when I call my set up function.
function debugit2() { console.log("Debugit2 Started...."); var ctx = SP.ClientContext.get_current(); var web = ctx.get_web(); functionToCall().done(function (returnedValue) { // do something with the returned value console.log(web.get_title()); }); function functionToCall() { var dfd = $.Deferred(function () { ctx.load(web); ctx.executeQueryAsync(function () { dfd.resolve(web); }, function (sender, args) { //throw an error var failmessage = args[1].get_message(); console.log(" oh no not again " + failmessage); }); }); return dfd.promise( /* do I chain here to say get my user or site or list objects */ ); } }
The only thing I need to do now is chain my promises to get the jsom objects: user, list, site etc, rename my function calls and then re-add my google delegate code. I think I hit the pain barrier on this ;-(
Just a quickup update ,
I have now tried a few methods for injecting my analytics script into my site or web. Looks like a script link is better than a script block . Also I am getting mixed results with a heavily branded site. Thanks for your previous actions as I did use it to inect a simpel script block into my iste
Got really stuck on John Liu's http://johnliu.net/blog/2015/12/convert-sharepoint-jsoms-executequeryasync-to-promise-in-the-prototype ... I seem never to get passed the error 'Protoype not defined' . Spoke to Hugh from Rencore about his custom SOD loader for sp.js and runtime.js but his answer gave me a headache trying to understand it lol.... Level 400 JavaScript springs to mind!
Annyway John kindly pointed at this one page add your script .....
Ok before I am ready to inject my final script I do need to remove the first script action with the client id shown ( see attachment) . It is part of the PnP CoreJavaScriptInjection which despite sucessfully deploying via VS2017 and removing via the UI , I can't find a way of remove this Action link.
- Steve BorgwardtMay 09, 2017Brass Contributor
Hi, Daniel
Glad to hear you are getting closer with your solution. In regards to that first client script action (PnP), I believe you still need that. But you may want to clean everything up first (remove all script actions) and then uses the PnP injection script method.
Thanks
- Daniel WesterdaleMay 11, 2017Iron Contributor
I applied the script, yesterday evening on our branded test site . The good news I am able to see some of my Custom Dimensions on our https://analytics.google.com portal. The bad news is we experienced some unfortunate side effects ... No ribbon bar on list settings, some web part pages not showing content.
Before I think of a rewriting say using JSCore & batching I think I will change sequence and also deal wth the clash shown below - this is an Add-in installed years ago that nobody seems to remember anything about ;-(. As anybody experienced similar issues with Custom Actions?
- Steve BorgwardtMay 11, 2017Brass Contributor
I haven't seen that happen unless you are doing something in your script that overrides or manipulates the SP DOM.
Maybe you are right about the sequence number and try that.
Thanks