
The division that handles the online cart has already installed AppInsights and have been collecting client-side javascript telemetry data for a while now. I work on the other content side of the website and we want to collect our own telemetry.
Looking at the code, the tracking logic and config is loaded and saved to a global variable: window.appInsights. That variable is reloaded every time a page is requested and the trackPageView() is called when the page loads.
If we were to install the ApplicationInsights client code in our part of the website, which is the typical entry point into our website, then the window.appInsights object will be initialized by us and use our instrumentationKey.
To prevent our collection from replacing theirs, we updated the client code to set our own global variable.
OLD:
<script type="text/javascript">
var appInsights = window.appInsights || function (config) {
...
window.appInsights = appInsights;
appInsights.trackPageView();
</script>
NEW:
<script type="text/javascript">
var appInsights = window.appInsightsSitecore || function (config) {
...
window.appInsightsSitecore = appInsights;
appInsights.trackPageView();
</script>
No comments:
Post a Comment