Last active
June 1, 2017 09:03
-
-
Save snobu/af7a5fd975e52a44571ccd1ec3c6cb87 to your computer and use it in GitHub Desktop.
HTML5 video events to App Insights (sending every 13 seconds or so)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
| <title>HTML5 video events to App Insights</title> | |
| <meta name="description" content=""> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <script type="text/javascript"> | |
| var appInsights=window.appInsights||function(config){ | |
| function i(config){t[config]=function(){var i=arguments;t.queue.push(function(){t[config].apply(t,i)})}}var t={config:config},u=document,e=window,o="script",s="AuthenticatedUserContext",h="start",c="stop",l="Track",a=l+"Event",v=l+"Page",y=u.createElement(o),r,f;y.src=config.url||"https://az416426.vo.msecnd.net/scripts/a/ai.0.js";u.getElementsByTagName(o)[0].parentNode.appendChild(y);try{t.cookie=u.cookie}catch(p){}for(t.queue=[],t.version="1.0",r=["Event","Exception","Metric","PageView","Trace","Dependency"];r.length;)i("track"+r.pop());return i("set"+s),i("clear"+s),i(h+a),i(c+a),i(h+v),i(c+v),i("flush"),config.disableExceptionTracking||(r="onerror",i("_"+r),f=e[r],e[r]=function(config,i,u,e,o){var s=f&&f(config,i,u,e,o);return s!==!0&&t["_"+r](config,i,u,e,o),s}),t | |
| }({ | |
| // Change instrumentationKey here to reflect your own AI instance: | |
| instrumentationKey:"61c75aec-ae11-483b-a126-665023ea73be" | |
| }); | |
| window.appInsights = appInsights; | |
| //appInsights.trackPageView(); | |
| var counter = 0; | |
| function sendTelemetry() { | |
| counter++; | |
| console.log(counter); | |
| if (counter > 13) { | |
| var theVideoId = document.getElementById("theVideoId"); | |
| var currentTime = Math.round(theVideoId.currentTime); | |
| console.log("Sending to App Insights currentTime = " + currentTime); | |
| // Send to App Insights | |
| appInsights.trackEvent('play', | |
| { | |
| 'currentTime': currentTime, | |
| 'streamUrl' : theVideoId.currentSrc | |
| }); | |
| counter = 0; | |
| } | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <video id="theVideoId" src="//ams1stor.blob.core.windows.net/asset-86509aa2-af36-4933-908b-3a61f5040573/Thievery%20Corporation%20-%20Forgotten_640x360_900.mp4" | |
| ontimeupdate="sendTelemetry()" | |
| type="video/mp4" | |
| autoplay | |
| controls /> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment