Skip to content

Commit

Permalink
Refactor it a bit and add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed May 17, 2020
1 parent a036897 commit cbc4e75
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/MSApplicationInsightsClient.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
<?php namespace Marchie\MSApplicationInsightsLaravel;

use Illuminate\Support\Str;

class MSApplicationInsightsClient extends InstrumentationKey
{
public function javascript()
{
if (isset($this->instrumentationKey)) {
return <<<SCRIPT
return $this->uglify($this->getCode());
}
}

public function uglify($code)
{
return str_replace(["\n","\r"], '', $code);
}

public function getCode()
{
return <<<SCRIPT
<!--Microsoft Azure Application Insights-->
<script type="text/javascript">
var appInsights=window.appInsights||function(config){
function s(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},r=document,f=window,e="script",o=r.createElement(e),i,u;for(o.src=config.url||"//az416426.vo.msecnd.net/scripts/a/ai.0.js",r.getElementsByTagName(e)[0].parentNode.appendChild(o),t.cookie=r.cookie,t.queue=[],i=["Event","Exception","Metric","PageView","Trace"];i.length;)s("track"+i.pop());return config.disableExceptionTracking||(i="onerror",s("_"+i),u=f[i],f[i]=function(config,r,f,e,o){var s=u&&u(config,r,f,e,o);return s!==!0&&t["_"+i](config,r,f,e,o),s}),t
Expand All @@ -17,6 +31,5 @@ function s(config){t[config]=function(){var i=arguments;t.queue.push(function(){
appInsights.trackPageView();
</script>
SCRIPT;
}
}
}
}

0 comments on commit cbc4e75

Please sign in to comment.