Skip to content

Commit

Permalink
remove Telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
Chizkiyahu committed Aug 21, 2023
1 parent 02eb227 commit 38c2383
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 536 deletions.
147 changes: 0 additions & 147 deletions source/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,152 +930,6 @@ base.BinaryReader = class {
}
};

base.Telemetry = class {

constructor(window) {
this._window = window;
this._navigator = window.navigator;
this._config = new Map();
this._metadata = {};
this._schema = new Map([
[ 'protocol_version', 'v' ],
[ 'tracking_id', 'tid' ],
[ 'hash_info', 'gtm' ],
[ '_page_id', '_p'],
[ 'client_id', 'cid' ],
[ 'language', 'ul' ],
[ 'screen_resolution', 'sr' ],
[ '_user_agent_architecture', 'uaa' ],
[ '_user_agent_bitness', 'uab' ],
[ '_user_agent_full_version_list', 'uafvl' ],
[ '_user_agent_mobile', 'uamb' ],
[ '_user_agent_model', 'uam' ],
[ '_user_agent_platform', 'uap' ],
[ '_user_agent_platform_version', 'uapv' ],
[ '_user_agent_wow64', 'uaw' ],
[ 'hit_count', '_s' ],
[ 'session_id', 'sid' ],
[ 'session_number', 'sct' ],
[ 'session_engaged', 'seg' ],
[ 'engagement_time_msec', '_et' ],
[ 'page_location', 'dl' ],
[ 'page_title', 'dt' ],
[ 'page_referrer', 'dr' ],
[ 'is_first_visit', '_fv' ],
[ 'is_external_event', '_ee' ],
[ 'is_new_to_site', '_nsi' ],
[ 'is_session_start', '_ss' ],
[ 'event_name', 'en' ]
]);
}

async start(measurement_id, client_id, session) {
this._session = session && typeof session === 'string' ? session.replace(/^GS1\.1\./, '').split('.') : null;
this._session = Array.isArray(this._session) && this._session.length >= 7 ? this._session : [ '0', '0', '0', '0', '0', '0', '0' ];
this._session[0] = Date.now();
this._session[1] = parseInt(this._session[1], 10) + 1;
this._engagement_time_msec = 0;
if (this._config.size > 0) {
throw new Error('Invalid session state.');
}
this.set('protocol_version', 2);
this.set('tracking_id', measurement_id);
this.set('hash_info', '2oebu0');
this.set('_page_id', Math.floor(Math.random() * 2147483648));
client_id = client_id ? client_id.replace(/^(GA1\.\d\.)*/, '') : null;
if (client_id && client_id.indexOf('.') !== 1) {
this.set('client_id', client_id);
} else {
const random = String(Math.round(0x7FFFFFFF * Math.random()));
const time = Date.now();
const value = [ random, Math.round(time / 1e3) ].join('.');
this.set('client_id', value);
this._metadata.is_first_visit = 1;
this._metadata.is_new_to_site = 1;
}
this.set('language', ((this._navigator && (this._navigator.language || this._navigator.browserLanguage)) || '').toLowerCase());
this.set('screen_resolution', (window.screen ? window.screen.width : 0) + 'x' + (window.screen ? window.screen.height : 0));
if (this._navigator && this._navigator.userAgentData && this._navigator.userAgentData.getHighEntropyValues) {
const values = await this._navigator.userAgentData.getHighEntropyValues([ 'platform', 'platformVersion', 'architecture', 'model', 'uaFullVersion', 'bitness', 'fullVersionList', 'wow64' ]);
if (values) {
this.set('_user_agent_architecture', values.architecture);
this.set('_user_agent_bitness', values.bitness);
this.set('_user_agent_full_version_list', Array.isArray(values.fullVersionList) ? values.fullVersionList.map((h) => encodeURIComponent(h.brand || '') + ';' + encodeURIComponent(h.version || '')).join('|') : '');
this.set('_user_agent_mobile', values.mobile ? 1 : 0);
this.set('_user_agent_model', values.model);
this.set('_user_agent_platform', values.platform);
this.set('_user_agent_platform_version', values.platformVersion);
this.set('_user_agent_wow64', values.wow64 ? 1 : 0);
}
}
this.set('hit_count', 1);
this.set('session_id', this._session[0]);
this.set('session_number', this._session[1]);
this.set('session_engaged', 0);
this._metadata.is_session_start = 1;
this._metadata.is_external_event = 1;
window.addEventListener('focus', () => this._update(true, undefined, undefined));
window.addEventListener('blur', () => this._update(false, undefined, undefined));
window.addEventListener('pageshow', () => this._update(undefined, true, undefined));
window.addEventListener('pagehide', () => this._update(undefined, false, undefined));
window.addEventListener('visibilitychange', () => this._update(undefined, undefined, window.document.visibilityState !== 'hidden'));
window.addEventListener('beforeunload', () => this._update() && this.send('user_engagement', {}));
}

get session() {
return this._session ? this._session.join('.') : null;
}

set(name, value) {
const key = this._schema.get(name);
if (value !== undefined && value !== null) {
this._config.set(key, value);
} else if (this._config.has(key)) {
this._config.delete(key);
}
this._cache = null;
}

get(name) {
const key = this._schema.get(name);
return this._config.get(key);
}

send(name, params) {
if (this._session) {
try {
params = Object.assign({ event_name: name }, this._metadata, /* { debug_mode: true },*/ params);
this._metadata = {};
this._update() && (params.engagement_time_msec = this._engagement_time_msec) && (this._engagement_time_msec = 0);
const build = (entires) => entires.map((entry) => entry[0] + '=' + encodeURIComponent(entry[1])).join('&');
this._cache = this._cache || build(Array.from(this._config));
const key = (name, value) => this._schema.get(name) || ('number' === typeof value && !isNaN(value) ? 'epn.' : 'ep.') + name;
const body = build(Object.entries(params).map((entry) => [ key(entry[0], entry[1]), entry[1] ]));
const url = 'https://analytics.google.com/g/collect?' + this._cache;
this._navigator.sendBeacon(url, body);
this._session[2] = this.get('session_engaged') || '0';
this.set('hit_count', this.get('hit_count') + 1);
} catch (e) {
// continue regardless of error
}
}
}

_update(focused, page, visible) {
this._focused = focused === true || focused === false ? focused : this._focused;
this._page = page === true || page === false ? page : this._page;
this._visible = visible === true || visible === false ? visible : this._visible;
const time = Date.now();
if (this._start_time) {
this._engagement_time_msec += (time - this._start_time);
this._start_time = 0;
}
if (this._focused !== false && this._page !== false && this._visible !== false) {
this._start_time = time;
}
return this._engagement_time_msec > 20;
}
};

base.Metadata = class {

Expand Down Expand Up @@ -1112,6 +966,5 @@ if (typeof module !== 'undefined' && typeof module.exports === 'object') {
module.exports.Complex128 = base.Complex128;
module.exports.BinaryStream = base.BinaryStream;
module.exports.BinaryReader = base.BinaryReader;
module.exports.Telemetry = base.Telemetry;
module.exports.Metadata = base.Metadata;
}
Loading

0 comments on commit 38c2383

Please sign in to comment.