PageSourceSearch

https://actionforhappiness.org/modules/custom/afh_mixpanel/js/mixpanel.js?tltti2

js actionforhappiness.org collected 2026-09-24 08:53:43 UTC 13,264 bytes, 313 lines download raw bytes

1/**
2 * @file
3 * Mixpanel integration.
4 */
5(function ($) {
6
7  'use strict';
8  var initialized = false;
9  function init() {
10    if (!initialized) {
11      initialized = true;
12      //load Mixpanel core
13      (function (f, b) { if (!b.__SV) { var e, g, i, h; window.mixpanel = b; b._i = []; b.init = function (e, f, c) { function g(a, d) { var b = d.split("."); 2 == b.length && ((a = a[b[0]]), (d = b[1])); a[d] = function () { a.push([d].concat(Array.prototype.slice.call(arguments, 0))); }; } var a = b; "undefined" !== typeof c ? (a = b[c] = []) : (c = "mixpanel"); a.people = a.people || []; a.toString = function (a) { var d = "mixpanel"; "mixpanel" !== c && (d += "." + c); a || (d += " (stub)"); return d; }; a.people.toString = function () { return a.toString(1) + ".people (stub)"; }; i = "disable time_event track track_pageview track_links track_forms track_with_groups add_group set_group remove_group register register_once alias unregister identify name_tag set_config reset opt_in_tracking opt_out_tracking has_opted_in_tracking has_opted_out_tracking clear_opt_in_out_tracking start_batch_senders people.set people.set_once people.unset people.increment people.append people.union people.track_charge people.clear_charges people.delete_user people.remove".split( " "); for (h = 0; h < i.length; h++) g(a, i[h]); var j = "set set_once union unset remove delete".split(" "); a.get_group = function () { function b(c) { d[c] = function () { call2_args = arguments; call2 = [c].concat(Array.prototype.slice.call(call2_args, 0)); a.push([e, call2]); }; } for ( var d = {}, e = ["get_group"].concat( Array.prototype.slice.call(arguments, 0)), c = 0; c < j.length; c++) b(j[c]); return d; }; b._i.push([e, f, c]); }; b.__SV = 1.2; e = f.createElement("script"); e.type = "text/javascript"; e.async = !0; e.src = "undefined" !== typeof MIXPANEL_CUSTOM_LIB_URL ? MIXPANEL_CUSTOM_LIB_URL : "file:" === f.location.protocol && "//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js".match(/^\/\//) ? "https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js" : "//cdn.mxpnl.com/libs/mixpanel-2-latest.min.js"; g = f.getElementsByTagName("script")[0]; g.parentNode.insertBefore(e, g); } })(document, window.mixpanel || []);
14      //init Mixpanel
15      mixpanel.init('5e75d28e03cbc3247dc0372cce4c8d1c', {debug: true, track_pageview: false,batch_requests: false, persistence: 'localStorage'});
16      var distinctid=getUrlParameter('u');
17      if(validateUserID(distinctid)){
18        mixpanel.identify(distinctid);
19        // Set user identification in session via AJAX
20        setUserIdentificationInSession(distinctid);
21      }
22    }
23  }
24  function validateUserID(str) {
25    return str.length === 64;
26  }
27  function getUrlParameter(name) {
28    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
29    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
30    var results = regex.exec(location.search);
31    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
32  }
33  function checkIdentify(trackEvent, eventName=false){
34    $.ajax({
35      url: Drupal.url('afh_mixpanel/session'),
36      type: 'GET',
37      dataType: 'json',
38      success: function (response) {
39        //console.log('Track Event:', trackEvent);
40        //console.log('AFH User ID:', response.afhUserID);
41        //console.log('trackTag:', response.trackTag);
42        if(trackEvent==response.trackTag){
43            mixpanel.identify(response.afhUserID);
44          
45          if(!eventName){
46            mixpanel.track(trackEvent);
47          }else{
48            mixpanel.track(trackEvent,{
49              Event: eventName
50            });
51          }
52          clearIdentify();
53        }
54        
55      },
56      error: function (xhr, status, error) {
57        console.error('Error fetching AFH User ID:', error);
58      }
59    });
60  }
61  function clearIdentify(){
62    $.ajax({
63      url: Drupal.url('afh_mixpanel/clear_session'),
64      type: 'GET',
65      dataType: 'json',
66      success: function (response) {
67        //console.log(response);
68        return response;
69      },
70      error: function (xhr, status, error) {
71        console.error('Error fetching AFH User ID:', error);
72      }
73    });
74  }
75
76  function setUserIdentificationInSession(userID){
77    $.ajax({
78      url: Drupal.url('afh_mixpanel/set_user_identification') + '?u=' + encodeURIComponent(userID),
79      type: 'GET',
80      dataType: 'json',
81      success: function (response) {
82        //console.log('User identification set:', response);
83        return response;
84      },
85      error: function (xhr, status, error) {
86        console.error('Error setting user identification:', error);
87      }
88    });
89  }
90
91  function mixpanelTrack(){
92
93    //Homepage - Page Load 
94    if (window.location.pathname === '/') {
95      mixpanel.track('web_home_page_load');
96    }
97    //Calendar - Page Load     
98    if (window.location.pathname === '/calendar') {
99      mixpanel.track('web_calendar_page_load');
100    }
101    //All Pages - "Join Movement Click"
102    $('#block-mainnavigation .join').on('click', function() {
103      mixpanel.track('web_join_movement_click');
104    });
105    //All Pages - Menu -> "Online Coaching" item click
106    $('#block-mainnavigation #coaching').on('click', function() {
107      if(!$(this).hasClass('clicked')){
108        mixpanel.track('web_menu_online_program_click');
109        $(this).addClass('clicked');
110      }
111    });  
112    //All Pages - "Join Movement" Form submitted with errors
113    //afh_moxpanel.module (afh_mixpanel_join_form_validation)
114
115    /* //All Pages - "Join Movement" Form submitted successfully (Not working afh_mixpanel_preprocess_html is executing twice)
116    $('body.node-12160.join_submit_success').on('click', function() {
117      mixpanel.track('join_movement_submit_success');
118    }); */ 
119    //All Pages - "Join Movement" Form submitted successfully
120    if ($('.track.web_join_movement_submit_success')[0]) {
121      mixpanel.track('web_join_movement_submit_success');
122    }else if ($('body#Join-Us-Confirmation-')[0]) {
123      checkIdentify('web_join_movement_submit_success');
124    }
125    //All Pages - iOS App Download
126    $('.ios.all').on('click', function() {
127      mixpanel.track('web_app_ios_click');
128    });  
129    //All Pages - Android App Download
130    $('.android.all').on('click', function() {
131      mixpanel.track('web_app_android_click');
132    });  
133    
134    //Homepage - "Take Action"
135    $('#takeaction').on('click', function() {
136      mixpanel.track('home_take_action_button_click');
137    });               
138
139    //Calendar - Calendar day popover, iOS download clicked
140    $('.ios.popup').on('click', function() {
141      mixpanel.track('web_calendar_day_ios_download_click');
142    });  
143    //Calendar - Calendar day popover, Android download clicked
144    $('.android.popup').on('click', function() {
145      mixpanel.track('web_calendar_day_android_download_click');
146    });  
147    //Calendar - Calendar Downloaded PDF
148    $('a.calendar_download_pdf').on('click', function() {
149      mixpanel.track('web_calendar_download_pdf');
150    });  
151    //Calendar - Calendar Downloaded JPG
152    $('a.calendar_download_jpg').on('click', function() {
153      mixpanel.track('web_calendar_download_jpg');
154    });  
155    //Calendar - Calendar Downloaded DOC
156    $('a.calendar_download_doc').on('click', function() {
157      mixpanel.track('web_calendar_download_doc');
158    });  
159    //Calendar - Calendar Downloaded ICS
160    $('#calendar_download_ics').on('click', function() {
161      mixpanel.track('web_calendar_download_ics');
162    });  
163    //Calendar - Calendar Downloaded View Google
164    $('#calendar_view_google').on('click', function() {
165      mixpanel.track('web_calendar_view_google');
166    }); 
167    //Calendar - Calendar day clicked
168    $('.view-calendar.view-display-id-block_1 a.calendaritem.activemonth').on('click', function() {
169      mixpanel.track('web_calendar_day_click');
170    });  
171
172    //Talks - Page Load 
173    if ($('body#Talks')[0]) {
174      mixpanel.track('web_talks_page_load');
175    }   
176    //Event Detail Page - Page Load 
177    if ($('body.page-node-type-talk')[0]) {
178      mixpanel.track('web_talks_event_page_load',{
179        Title: $('.talkintro .featurehead span').html()
180      });
181    }   
182    //Event Detail Page - Eventbrite Widget Started
183    $('button.trigger-event').on('click', function() {
184      mixpanel.track('web_talks_event_eventbrite_triggered',{
185        Title: $('.talkintro .featurehead span').html()
186      });
187    });  
188    //Event Detail Page - Eventbrite Widget Completed Successfully
189    //theme/afh/templates/node/node--talk.html.twig callback
190
191    //Groups > All - Page Load 
192    if ($('body#Join-a-Local-Group')[0]) {
193      mixpanel.track('web_groups_page_load');
194    }   
195    //Groups > Specific - Page Load 
196    if ($('body.page-node-type-group')[0]) {
197      mixpanel.track('web_groups_individual_page_load',{
198        Title: $('.headtextcontainer h1').html()
199      });
200    }  
201    //Groups > Specific - Form Submit Error
202    //afh_moxpanel.module (afh_mixpanel_join_form_validation)
203
204    //Groups > Specific - Form Submit Success
205    if ($('.track.web_groups_individual_form_submit_success')[0]) {
206      mixpanel.track('web_groups_individual_form_submit_success');
207    }else if ($('body#Group-Join-Confirmation-')[0]) {
208      checkIdentify('web_groups_individual_form_submit_success');
209    }
210    //Course > All - Page Load 
211    if ($('body#Happiness-Habits-Course')[0]) {
212      mixpanel.track('web_courses_page_load');
213    }   
214    //Course > Specific - Page Load 
215    if ($('.product--course')[0]) {
216      mixpanel.track('web_courses_individual_page_load',{
217        Title: $('.product--course .talkintro .featurehead div').html()
218      });
219    }  
220    //Course > Specific - Signup Button Click
221    $('.product--course a#course-singup-click').click(function(e){
222      mixpanel.track('web_courses_individual_signup_click',{
223        Title: $('.product--course .talkintro .featurehead div').html()
224      });
225    })
226    //Course > Specific - Signup Form Submit Error
227    if ($('.track.courses')[0]) {
228      mixpanel.track('web_courses_individual_signup_fail',{
229        Errors: $('.track.courses').html()
230      });
231    }
232    $('.commerce-order-item-add-to-cart-form.webform-submission-form input.form-submit').click(function(e){
233      var form = $('.commerce-order-item-add-to-cart-form.webform-submission-form')[0];
234      if (!form.checkValidity()) {
235        mixpanel.track('web_courses_individual_signup_fail');
236      }
237    })
238
239    //Course > Specific - Signup Form Submit Before payment
240    if ($('.view-commerce-cart-form .views-form > form')[0]) {
241      var cartID=$('.view-commerce-cart-form .views-form > form').attr('id');
242      var stringToRemove = "views-form-commerce-cart-form-default-";
243      var cartID = cartID.replace(stringToRemove, "");
244      checkIdentify('web_courses_individual_signup_success', 'Cart ID: '+cartID);
245      /*
246      mixpanel.track('web_courses_individual_signup_success',{
247        Event: 'Cart ID: '+cartID
248      });
249      */
250    }  
251    //Course > Specific - Signup Form Submit Success After paypal
252    if ($('body#Checkout.checkout_complete')[0]) {
253      mixpanel.track('web_courses_paypal_complete',{
254        Event: $('body#Checkout').data('event-title')
255      });
256    }  
257    //10 Keys - Page Load 
258    if ($('body#_0-Keys-to-Happier-Living')[0]) {
259      mixpanel.track('web_10keys_page_load');
260    }   
261    //10 Keys > Specific - Page Load 
262    if ($('body.page-node-type-tab-content')[0]) {
263      mixpanel.track('web_10keys_individual_page_load',{
264        Title: $('.keytabcontent > .container > h1 span').html()
265      });
266    }  
267    //10 Keys - Page Load 
268    if ($('body#About-Us')[0]) {
269      mixpanel.track('web_aboutus_page_load');
270    }   
271    //10 Keys > Book - Page Load 
272    if ($('body.node-574')[0]) {
273      mixpanel.track('web_10keys_book_page_load');
274    }   
275    //Volunteer - Page Load 
276    if ($('body#Volunteer')[0]) {
277      mixpanel.track('web_volunteer_page_load');
278    }   
279    //Volunteer Training - Join Volunteer Training' Button Click 
280    $('.webform-submission-module-0-volunteer-training-entr-form #edit-wizard-next').on('click', function() {
281      mixpanel.track('web_volunteer_join_training');
282    });  
283    //Volunteer Training - Volunteer start training webform complete
284    //theme/afh/templates/modules/webform/webform-confirmation--module_0_volunteer_training_entr.html.twig
285  }
286  Drupal.behaviors.afh_mixpanel = {
287    attach: function (context, settings) {
288      init();
289      
290      $(document).ready(function() {
291        //check if the user filled the form and creates an user id
292        var userid;
293        if($('.mxpuid')[0]){
294          userid=$('.mxpuid').data('userid');
295          mixpanel.identify(userid);
296          //Clear session variable from user;
297          clearIdentify();
298        }/*else if ($('body#Join-Us-Confirmation-')[0]) {
299          userid=$('body').data('userid');
300          mixpanel.identify(userid);
301          $('body').data('userid','');
302        }*/
303        $('body').removeAttr('data-userid');
304        mixpanelTrack();
305        
306        if($('div[data-drupal-messages] > div > .track')[0] && $('div[data-drupal-messages] > div').length==1){
307          $('div[data-drupal-messages]').fadeOut(0);
308        }
309      });
310    }
311  }
312
313})(jQuery, Drupal, drupalSettings);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.