|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <!-- |
| 5 | + If you are serving your web app in a path other than the root, change the |
| 6 | + href value below to reflect the base path you are serving from. |
| 7 | +
|
| 8 | + The path provided below has to start and end with a slash "/" in order for |
| 9 | + it to work correctly. |
| 10 | +
|
| 11 | + For more details: |
| 12 | + * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base |
| 13 | +
|
| 14 | + This is a placeholder for base href that will be replaced by the value of |
| 15 | + the `--base-href` argument provided to `flutter build`. |
| 16 | + --> |
| 17 | + <base href="$FLUTTER_BASE_HREF"> |
| 18 | + |
| 19 | + <meta charset="UTF-8"> |
| 20 | + <meta content="IE=Edge" http-equiv="X-UA-Compatible"> |
| 21 | + <meta name="description" content="Demonstrates how to use the mixpanel_flutter plugin."> |
| 22 | + |
| 23 | + <!-- iOS meta tags & icons --> |
| 24 | + <meta name="apple-mobile-web-app-capable" content="yes"> |
| 25 | + <meta name="apple-mobile-web-app-status-bar-style" content="black"> |
| 26 | + <meta name="apple-mobile-web-app-title" content="mixpanel_flutter_example"> |
| 27 | + <link rel="apple-touch-icon" href="icons/Icon-192.png"> |
| 28 | + |
| 29 | + <title>mixpanel_flutter_example</title> |
| 30 | + <link rel="manifest" href="manifest.json"> |
| 31 | + <script type="text/javascript"> |
| 32 | + (function(f,b){if(!b.__SV){var e,g,i,h;window.mixpanel=b;b._i=[];b.init=function(e,f,c){function g(a,d){var b=d.split(".");2==b.length&&(a=a[b[0]],d=b[1]);a[d]=function(){a.push([d].concat(Array.prototype.slice.call(arguments,0)))}}var a=b;"undefined"!==typeof c?a=b[c]=[]:c="mixpanel";a.people=a.people||[];a.toString=function(a){var d="mixpanel";"mixpanel"!==c&&(d+="."+c);a||(d+=" (stub)");return d};a.people.toString=function(){return a.toString(1)+".people (stub)"};i="disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split(" "); |
| 33 | + for(h=0;h<i.length;h++)g(a,i[h]);var j="set set_once union unset remove delete".split(" ");a.get_group=function(){function b(c){d[c]=function(){call2_args=arguments;call2=[c].concat(Array.prototype.slice.call(call2_args,0));a.push([e,call2])}}for(var d={},e=["get_group"].concat(Array.prototype.slice.call(arguments,0)),c=0;c<j.length;c++)b(j[c]);return d};b._i.push([e,f,c])};b.__SV=1.2;e=f.createElement("script");e.type="text/javascript";e.async=!0;e.src="undefined"!==typeof MIXPANEL_CUSTOM_LIB_URL? |
| 34 | + MIXPANEL_CUSTOM_LIB_URL:"file:"===f.location.protocol&&"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//)?"https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js":"//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js";g=f.getElementsByTagName("script")[0];g.parentNode.insertBefore(e,g)}})(document,window.mixpanel||[]); |
| 35 | + </script> |
| 36 | +</head> |
| 37 | +<body> |
| 38 | + <!-- This script installs service_worker.js to provide PWA functionality to |
| 39 | + application. For more information, see: |
| 40 | + https://developers.google.com/web/fundamentals/primers/service-workers --> |
| 41 | + <script> |
| 42 | + var serviceWorkerVersion = null; |
| 43 | + var scriptLoaded = false; |
| 44 | + function loadMainDartJs() { |
| 45 | + if (scriptLoaded) { |
| 46 | + return; |
| 47 | + } |
| 48 | + scriptLoaded = true; |
| 49 | + var scriptTag = document.createElement('script'); |
| 50 | + scriptTag.src = 'main.dart.js'; |
| 51 | + scriptTag.type = 'application/javascript'; |
| 52 | + document.body.append(scriptTag); |
| 53 | + } |
| 54 | + |
| 55 | + if ('serviceWorker' in navigator) { |
| 56 | + // Service workers are supported. Use them. |
| 57 | + window.addEventListener('load', function () { |
| 58 | + // Wait for registration to finish before dropping the <script> tag. |
| 59 | + // Otherwise, the browser will load the script multiple times, |
| 60 | + // potentially different versions. |
| 61 | + var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion; |
| 62 | + navigator.serviceWorker.register(serviceWorkerUrl) |
| 63 | + .then((reg) => { |
| 64 | + function waitForActivation(serviceWorker) { |
| 65 | + serviceWorker.addEventListener('statechange', () => { |
| 66 | + if (serviceWorker.state == 'activated') { |
| 67 | + console.log('Installed new service worker.'); |
| 68 | + loadMainDartJs(); |
| 69 | + } |
| 70 | + }); |
| 71 | + } |
| 72 | + if (!reg.active && (reg.installing || reg.waiting)) { |
| 73 | + // No active web worker and we have installed or are installing |
| 74 | + // one for the first time. Simply wait for it to activate. |
| 75 | + waitForActivation(reg.installing || reg.waiting); |
| 76 | + } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) { |
| 77 | + // When the app updates the serviceWorkerVersion changes, so we |
| 78 | + // need to ask the service worker to update. |
| 79 | + console.log('New service worker available.'); |
| 80 | + reg.update(); |
| 81 | + waitForActivation(reg.installing); |
| 82 | + } else { |
| 83 | + // Existing service worker is still good. |
| 84 | + console.log('Loading app from service worker.'); |
| 85 | + loadMainDartJs(); |
| 86 | + } |
| 87 | + }); |
| 88 | + |
| 89 | + // If service worker doesn't succeed in a reasonable amount of time, |
| 90 | + // fallback to plaint <script> tag. |
| 91 | + setTimeout(() => { |
| 92 | + if (!scriptLoaded) { |
| 93 | + console.warn( |
| 94 | + 'Failed to load app from service worker. Falling back to plain <script> tag.', |
| 95 | + ); |
| 96 | + loadMainDartJs(); |
| 97 | + } |
| 98 | + }, 4000); |
| 99 | + }); |
| 100 | + } else { |
| 101 | + // Service workers not supported. Just drop the <script> tag. |
| 102 | + loadMainDartJs(); |
| 103 | + } |
| 104 | + </script> |
| 105 | +</body> |
| 106 | +</html> |
0 commit comments