This repository has been archived by the owner on Sep 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathplatinum-sw-offline-analytics.html
60 lines (58 loc) · 2.61 KB
/
platinum-sw-offline-analytics.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<script>
/**
* The `<platinum-sw-offline-analytics>` element registers a service worker
* handler to intercept requests for Google Analytics pings.
*
* If the HTTP GET for the ping is successful (because the browser is online),
* then everything proceeds as it normally would. If the HTTP GET fails, the
* ping request is saved to IndexedDB, and each time the service worker script
* starts up it will attempt to "replay" those saved ping requests, giving up
* after one day has passed.
*
* The
* [`qt`](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters#qt)
* URL parameter is automatically added to the replayed HTTP GET and set to the
* number of milliseconds that has passed since the initial ping request was
* attempted, to ensure that the original time attribution is correct.
*
* `<platinum-sw-offline-analytics>` does not take care of setting up Google
* Analytics on your page, and assumes that you have [properly
* configured](https://support.google.com/analytics/answer/1008080) the Google
* Analytics tracking code registered elsewhere on your page.
*
* Since `<platinum-sw-offline-analytics>` is only useful if the page that is
* being tracked with Google Analytics works offline, it's best used in
* conjunction with the `<platinum-sw-cache>` element, which takes care of
* caching your site's resources and serving them while offline.
*
* A basic configuration is
*
* <platinum-sw-register auto-register>
* <platinum-sw-offline-analytics></platinum-sw-offline-analytics>
* <platinum-sw-cache></platinum-sw-cache>
* </platinum-sw-register>
*
*/
Polymer({
is: 'platinum-sw-offline-analytics',
_getParameters: function(baseURI) {
return Promise.resolve({
importscript: new URL('bootstrap/simple-db.js', baseURI).href,
importscriptLate: [
new URL('bootstrap/sw-toolbox-setup.js', baseURI).href,
new URL('bootstrap/offline-analytics.js', baseURI).href
]
});
}
});
</script>