-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathplugin-analytics.html
More file actions
203 lines (176 loc) · 6.8 KB
/
Copy pathplugin-analytics.html
File metadata and controls
203 lines (176 loc) · 6.8 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!-- Plugin by Cory Chaplin (elephantman@europnet.org) - http://www.europnet.org - 04/2020 -->
<script>
function loadAnalytics() {
let gaScript = document.createElement('script');
gaScript.setAttribute('src', 'https://www.googletagmanager.com/gtag/js?id=UA-36932919-2');
document.head.appendChild(gaScript);
}
loadAnalytics();
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-36932919-2', {
'page_title' : 'Login',
'page_path': '/login'
});
gtag('event', 'Login', {
event_category: 'KiwiV2',
event_label: 'Ready',
value: true
});
/* gtag('event', <action>, {
'event_category': <category>,
'event_label': <label>,
'value': <value>
});
ga('send', {
hitType: 'event',
eventCategory: 'Video',
eventAction: 'play',
eventLabel: 'cats.mp4'
}); */
/*
Ident layout, forged by the `username` plugin:
[source][browser][os][8 random] — 11 chars.
The mobile app embeds this same web client, so its events land on the web
stream and are otherwise indistinguishable from a browser. The source char
is the only marker we have.
*/
const IDENT_SOURCES = {
c: 'chat-fr', e: 'europnet', a: 'andromede', f: 'fantasya',
l: '123love', v: 'loovchat', m: 'mikochat', x: 'xchat-fr',
z: 'app-mobile', o: 'other', d: 'direct',
};
function identProperties(network) {
const ident = (network && network.username) || '';
if (ident.length !== 11) {
return { client: 'unknown', source: 'unknown' };
}
const source = ident.charAt(0);
return {
client: source === 'z' ? 'app' : 'web',
source: IDENT_SOURCES[source] || 'unknown',
};
}
function loadAds() {
let gadScript = document.createElement('script');
gadScript.setAttribute('src', 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-7308685930931350');
gadScript.setAttribute('crossorigin', 'anonymous');
let consentScript = document.createElement('script');
consentScript.setAttribute('src', 'https://fundingchoicesmessages.google.com/i/pub-7308685930931350?ers=1');
consentScript.setAttribute('nonce', '8E3jRfZNaNqrTM-Ehy_Qqw');
document.head.appendChild(gadScript);
document.head.appendChild(consentScript);
}
setTimeout(doAds, 300000);
function doAds() {
let buffers = kiwi.state.getBuffersWithUser(kiwi.state.getActiveNetwork().id, kiwi.state.getActiveNetwork().nick);
let regex = /[2-9][0-9] M/; // Men >20 years old
// Check channels & male & not mobile app
if((regex.test(kiwi.state.getActiveNetwork().gecos) &&
kiwi.state.getActiveNetwork().username.substring(0, 1) !== 'z') &&
(_.find(buffers, function(value) {
return ['#sexe', '#bdsm', '#scenario', '#erotisme', '#sexcam', '#sexe-gay',
'#123love', '#andromede', '#algeriens', '#maroc', '#afrique',
'#rencontres', '#transgenre', '#gay&lesb'].includes(value.name);
}) !== undefined)) {
gtag('event', 'Ads', {
event_category: 'Loaded',
event_label: 'IgniteConsent',
value: true
});
(function() {
function signalGooglefcPresent() {
if (!window.frames['googlefcPresent']) {
if (document.body) {
const iframe = document.createElement('iframe');
iframe.style = 'width: 0; height: 0; border: none; z-index: -1000; left: -1000px; top: -1000px;';
iframe.style.display = 'none';
iframe.name = 'googlefcPresent';
document.body.appendChild(iframe);
} else {
setTimeout(signalGooglefcPresent, 0);
}
}
}
signalGooglefcPresent();
})();
loadAds();
document.querySelector('#navbar li.xflirt-link').style.display = '';
}
}
/* Bind kiwi events to GA */
kiwi.plugin('analytics', function(kiwi) {
kiwi.on('network.connecting', function(event) {
// Set as early as possible: unlike ASL below, these are known upfront,
// so every subsequent event carries them.
gtag('set', 'user_properties', identProperties(event && event.network));
gtag('event', 'Login', {
event_category: 'KiwiV2',
event_label: 'Connecting',
value: true
});
});
kiwi.on('irc.registered', function(event, network) {
// Re-set: `network` is guaranteed here, so this covers the case where
// the connecting handler ran without one.
gtag('set', 'user_properties', identProperties(network));
gtag('event', 'Server', {
event_category: 'KiwiV2',
event_label: 'Connected',
value: true
});
gtag('event', 'page_view', {
page_path: '/connected',
page_title: 'Connected'
});
setTimeout(function() {
let userObj = kiwi.state.getUser(network.id, network.nick);
let asl = (userObj && userObj.asl) ? userObj.asl : {};
gtag('set', 'user_properties', {
'age': asl.a || 'unknown',
'gender': asl.s || 'unknown',
'city': asl.l || 'unknown',
});
}, 5000);
});
const gamesCfg = (kiwi.state.settings && kiwi.state.settings['plugin_kiwi_games']) || null;
const anyGameEnabled = gamesCfg && ['tictactoe', 'connectfour', 'pictionary'].some(function(id) {
return !gamesCfg[id] || gamesCfg[id].enabled !== false;
});
if (anyGameEnabled) {
kiwi.on('plugin-kiwi-games.game-proposed', function(data) {
gtag('event', 'Games', {
event_category: data.game,
event_label: 'proposed',
value: true
});
});
kiwi.on('plugin-kiwi-games.game-started', function(data) {
gtag('event', 'Games', {
event_category: data.game,
event_label: 'started',
value: true
});
});
kiwi.on('plugin-kiwi-games.game-completed', function(data) {
gtag('event', 'Games', {
event_category: data.game,
event_label: 'completed',
value: true
});
});
}
// Count minutes
setInterval(function(){
if(kiwi.state.getActiveNetwork() !== undefined &&
kiwi.state.getActiveNetwork().state === 'connected') {
gtag('event', 'Minutes', {
event_category: 'KiwiV2',
event_label: '+1',
value: true
});
}
}, 60000);
});
</script>