NikolayBezay

Yad2 custom GA events depends to the user device.

Feb 19th, 2021
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.24 KB | None | 0 0
  1. <script>
  2. (function() {
  3.     function getTrackerName(device) {
  4.         var TRACKER_ID_DT = 'UA-708051-1';
  5.         var TRACKER_ID_MOB = 'UA-708051-35';
  6.  
  7.         var trackers = ga.getAll();
  8.         var trackerName = 't0';
  9.         trackers.forEach(function(tracker) {
  10.             var goalTrackerName = tracker.get('name');
  11.             var goalTrackerId = tracker.get('trackingId');
  12.             if (device === 'desktop' && goalTrackerId === TRACKER_ID_DT) {
  13.                trackerName = goalTrackerName;
  14.             } else if (device != 'desktop' && goalTrackerId === TRACKER_ID_MOB) {
  15.                trackerName = goalTrackerName;
  16.             }
  17.            
  18.         });
  19.         return trackerName;
  20.     }
  21.  
  22.     adoric.on('lightbox:after:show', function(e) {
  23.         var trackerName = getTrackerName(e.lightbox.options.type);
  24.         window.ga && window.ga(trackerName + '.send', 'event', {
  25.            eventCategory: 'Adoric - ' + e.lightbox.options.campaignTitle,
  26.            eventAction: 'impression',
  27.            eventLabel: 'Adoric - '  + e.lightbox.options.title
  28.        });
  29.     });
  30.     adoric.on('lightbox:after:close', function(e) {
  31.         var trackerName = getTrackerName(e.lightbox.options.type);
  32.         window.ga && window.ga(trackerName + '.send', 'event', {
  33.            eventCategory: 'Adoric - ' + e.lightbox.options.campaignTitle,
  34.            eventAction: 'Close or Transition',
  35.            eventLabel: 'Adoric - '  + e.lightbox.options.title
  36.        });
  37.     });
  38.     adoric.on('lightbox:after:click', function(e) {
  39.         var trackerName = getTrackerName(e.lightbox.options.type);
  40.         window.ga && window.ga(trackerName + '.send', 'event', {
  41.            eventCategory: 'Adoric - ' + e.lightbox.options.campaignTitle,
  42.            eventAction: 'Click',
  43.            eventLabel: 'Adoric - '  + e.lightbox.options.title
  44.        });
  45.     });
  46.     adoric.on('form:after:submit', function(e) {
  47.         var trackerName = getTrackerName(e.lightbox.options.type);
  48.         window.ga && window.ga(trackerName + '.send', 'event', {
  49.            eventCategory: 'Adoric - ' + e.lightbox.options.campaignTitle,
  50.            eventAction: 'Click',
  51.            eventLabel: 'Adoric - '  + e.lightbox.options.title
  52.        });
  53.     });
  54. })();
  55. </script>
  56.  
Advertisement
Add Comment
Please, Sign In to add comment