Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* eslint-disable prefer-rest-params */
- import DiadocMain from './diadoc-main';
- let gaDiadoc = () => {};
- if (!window.ga_diadoc && !process.env.TESTING) {
- ((w, d, s, src, ga_diadoc, a, m) => {
- w['GoogleAnalyticsObject'] = ga_diadoc;
- w[ga_diadoc] = w[ga_diadoc]
- || (() => (w[ga_diadoc].q = w[ga_diadoc].q || []).push(arguments));
- w[ga_diadoc].l = 1 * new Date();
- a = d.createElement(s);
- m = d.getElementsByTagName(s)[0];
- a.async = 1;
- a.src = src;
- m.parentNode.insertBefore(a, m);
- a.onload = () => {
- window.ga_diadoc('create', 'UA-17444089-1', 'auto', {
- 'allowLinker': true
- });
- const userId = DiadocMain.getCurrentUserId();
- const orgId = DiadocMain.getCurrentOrgId();
- if (userId != null) {
- window.ga_diadoc('set', '&uid', userId);
- window.ga_diadoc('set', 'dimension1', userId);
- }
- if (orgId != null) {
- window.ga_diadoc('set', 'dimension2', orgId);
- }
- window.ga_diadoc('require', 'linker');
- window.ga_diadoc('linker:autoLink', ['www.diadoc.ru']);
- window.ga_diadoc('send', 'pageview');
- };
- })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga_diadoc');
- gaDiadoc = (e, label, eventValue) => {
- const fieldsObject = eventValue === undefined ? undefined : { eventValue };
- if (window.ga_diadoc) {
- console.log(`ga->${e}`);
- window.ga_diadoc('send', 'event', 'system', e, label === undefined ? '' : label, fieldsObject);
- }
- };
- //TODO: if testing env, then write ga to localStorage
- } else if (process.env.TESTING) {
- window.ga_diadoc = (send, ev, sys, action, label, count, metrics) => {
- let current = localStorage.getItem('diadoc_ga') || '';
- let tmp = action;
- if (label) tmp += `$${label}`;
- if (count) tmp += `$${JSON.stringify(count)}`;
- if (metrics) tmp += `$${JSON.stringify(metrics)}`;
- current += `${tmp}|`;
- localStorage.setItem('diadoc_ga', current);
- };
- window.ga_diadoc.reset = () => localStorage.setItem('diadoc_ga', '');
- window.ga_diadoc.getLog = () => localStorage.getItem('diadoc_ga') || '';
- gaDiadoc = (e, label, count, metrics) => {
- window.ga_diadoc('send', 'event', 'system', e, label === undefined ? '' : label, count, metrics);
- };
- }
- if (typeof module !== 'undefined' && module.exports) {
- module.exports = gaDiadoc;
- }
- if (typeof dd !== 'undefined') {
- dd.ui = { ...dd.ui, ga_diadoc: gaDiadoc };
- }
Add Comment
Please, Sign In to add comment