-
Notifications
You must be signed in to change notification settings - Fork 79
/
google-analytics-loader.html
101 lines (82 loc) · 2.46 KB
/
google-analytics-loader.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../google-signin/google-signin-aware.html">
<link rel="import" href="../google-apis/google-client-loader.html">
<link rel="import" href="../promise-polyfill/promise-polyfill-lite.html">
<!--
google-analytics-loader is used internally by elements that need to know api state, and user state.
Loads gapi.client.analytics, and watches user signed-in state.
@element google-analytics-loader
@demo
@homepage https://googlewebcomponents.github.io/google-analytics
-->
<dom-module id="google-analytics-loader">
<template>
<google-client-loader id="api"
name="analytics"
version="v3"
on-google-api-load="handleApiLoad"
on-google-api-load-error="handleApiFailedToLoad"></google-client-loader>
<google-signin-aware
scopes="https://www.googleapis.com/auth/analytics.readonly"
on-google-signin-aware-success="handleAuthSuccess"
on-google-signin-aware-signed-out="handleAuthSignout"></google-signin-aware>
</template>
</dom-module>
<script>
(function() {
'use strict';
Polymer({
is: 'google-analytics-loader',
properties: {
/**
* True when user is authorized, and api is loaded
* @attribute allReady
* @type {Boolean}
*/
allReady: {
type: Boolean,
computed: 'computeAllReady(apiReady, authorized)',
notify: true
},
/**
* True when api is loaded
* @attribute apiReady
* @type {Boolean}
*/
apiReady: {
type: Boolean,
value: false,
notify: true,
readOnly: true
},
/**
* True when user is authorized
* @attribute authorized
* @type {Boolean}
*/
authorized: {
type: Boolean,
value: false,
notify: true,
readOnly: true
}
},
computeAllReady: function(apiReady, authorized) {
return apiReady && authorized;
},
handleApiLoad: function() {
this._setApiReady(true);
},
handleApiFailedToLoad: function(ev, detail) {
this._setApiReady(false);
console.error("Api failed to load: ", this.$.api.name, this.$.api.version);
},
handleAuthSuccess: function() {
this._setAuthorized(true);
},
handleAuthSignout: function() {
this._setAuthorized(false);
}
});
}());
</script>