1jQuery(document).ready(function($) { 2 3 if(jQuery('.umgecrm-casl-country-block').length) { 4 jQuery('.umgecrm-casl-country-block select.umgecrm-casl-country-selector').change(function() { 5 var country_code = jQuery(this).val(); 6 UMGECRM.check_casl(country_code); 7 }); 8 } else { 9 if(typeof AEJSWP !== 'undefined') { 10 //add waiter that makes AE Connect wait before executing user optins. This is required when we are waiting for Lytics Cookie ID 11 AEJSWP.get_user_country('UMGECRM.check_casl'); 12 } 13 } 14}); 15 16if(typeof UMGECRM.sub_data !== 'undefined' && typeof UMGECRM.sub_data.ecrm !== 'undefined' && UMGECRM.sub_data.ecrm == 'umgapi' && UMGECRM.lytics_env !== 'none') { 17 if(typeof AEJSWP !== 'undefined') { 18 //add waiter that makes AE Connect wait before executing user optins. This is required when we are waiting for Lytics Cookie ID 19 AEJSWP.add_wait_for_event('send_user_optins'); 20 } 21 22 /** 23 * Lytics Callback Handler 24 */ 25 !function(l,a){a.liosetup=a.liosetup||{},a.liosetup.callback=a.liosetup.callback||[],a.liosetup.addEntityLoadedCallback=function(l,o){if("function"==typeof a.liosetup.callback){var i=[];i.push(a.liosetup.callback),a.liosetup.callback=i}a.lio&&a.lio.loaded?l(a.lio.data):o?a.liosetup.callback.unshift(l):a.liosetup.callback.push(l)}}(document,window); 26 27 // Custom Callback Function 28 window.liosetup.addEntityLoadedCallback(function(data){ 29 30 //get lytics cookie uid 31 var lytics_uid = window.jstag.getid(); 32 33 //append the lytics uid to user data object so it can be used when sending optin API call 34 AEJSWP.add_data_filter('filter__optin_user_data', function(data) { 35 data['lytics_uid'] = lytics_uid; 36 37 return data; 38 }); 39 40 AEJSWP.add_data_filter('filter__redirect_login_return_url', function(return_url) { 41 return AEJSWP.addURLParameter(return_url, 'lytics-uid', lytics_uid); 42 }); 43 44 AEJSWP.execute_wait_for_event('send_user_optins'); 45 }); 46} 47 48//Check if user is from Canada and amend any fields that require different labels for Canada 49UMGECRM.check_casl = function(country) { 50 if(country == 'CA') { 51 //user country is Canada so let's use CASL labels 52 jQuery('.umgecrm-adhoc-block[data-umgecrm-casl="1"]').each(function() { 53 jQuery('.umgecrm-text-container').each(function() { 54 if(jQuery('.umgecrm-casl', jQuery(this)).length) { 55 jQuery('.umgecrm-casl', jQuery(this)).show(); 56 jQuery('.umgecrm-non-casl', jQuery(this)).hide(); 57 } 58 }); 59 }); 60 } 61}; 62 63//Add event listener for AEJS ready 64AEJSWP.add_aejsready_handler("UMGECRM.ae_wpaejsready"); 65UMGECRM.ae_wpaejsready = function(aeJS) { 66 aeJS.events.onLogin.addHandler(UMGECRM.ae_login_handle); 67 aeJS.events.onUser.addHandler(UMGECRM.ae_user_handle); 68}; 69 70 71//Function executed when AE Framework logs in user 72UMGECRM.ae_login_handle = function(ae_user) { 73 74 //find all adhoc ecrm forms and save their opt-in states to localStorage so they can be executed once AE onUser event fires 75 //if AJAX login is not used then onUSer event will fire after page refresh (that's why save states in localStorage) 76 jQuery('.umgecrm-adhoc-block[data-umgecrm-submission-type="auth-connect"]').each(function() { 77 UMGECRM.set_adhoc_block_states(jQuery(this), ae_user); 78 }); 79}; 80 81//Function executed when AE framework returns a user object to the client 82UMGECRM.ae_user_handle = function(ae_user) { 83 UMGECRM.update_adhoc_blocks(ae_user); 84 85 //AE user logged in so we can execute opt-ins that are set to 'auth-connect' submission type 86 jQuery('.umgecrm-adhoc-block[data-umgecrm-submission-type="auth-connect"]').each(function() { 87 var subs = UMGECRM.get_adhoc_block_states(jQuery(this), ae_user); 88 if(typeof subs !== 'undefined') { 89 UMGECRM.execute_adhoc_block(jQuery(this), ae_user, subs); 90 UMGECRM.clear_adhoc_block_states(jQuery(this), ae_user); 91 } 92 }); 93 94 //Add listeners to submit buttons where adhoc submission type is set to submit-button 95 jQuery('.umgecrm-adhoc-block[data-umgecrm-submission-type="submit-button"]').each(function() { 96 var block = jQuery(this); 97 jQuery('.umgecrm-submit-button button', jQuery(this)).click(function(e) { 98 e.preventDefault(); 99 UMGECRM.execute_adhoc_block(block, ae_user); 100 }); 101 }); 102}; 103 104//check which adhoc block have been complete and set complete message if they are complete 105//complete states are checked and saved inside of localStorage 106UMGECRM.update_adhoc_blocks = function(ae_user) { 107 jQuery('.umgecrm-adhoc-block').each(function() { 108 var adhoc_id = jQuery(this).attr('data-adhoc-id'); 109 110 if(UMGECRM.session_check_adhoc_exists(adhoc_id, ae_user)) { 111 jQuery(this).children('div').hide(); 112 jQuery('.umgecrm-complete-block', jQuery(this)).show(); 113 } 114 }); 115}; 116 117//run opt-in actions from specified ad-hoc block/shortcode 118UMGECRM.execute_adhoc_block = function(block, ae_user, subs) { 119 var adhoc_id = jQuery(block).attr('data-adhoc-id'); 120 if(!UMGECRM.session_check_adhoc_exists(adhoc_id, ae_user)) { 121 UMGECRM.session_set_adhoc(adhoc_id, ae_user); 122 123 jQuery.ajax({ 124 url: UMGECRM.ajaxurl, 125 type: 'post', 126 data: { 127 action: 'execute_adhoc_block', 128 user: ae_user, 129 subs: subs, 130 adhoc_id: adhoc_id 131 }, 132 success: function(response) { 133 UMGECRM.update_adhoc_blocks(ae_user); 134 //track analytics event for adhoc form 135 UMGECRM.trackEvent('optin_success_adhoc', {form_id: adhoc_id, user: ae_user, subs: subs}); 136 } 137 }); 138 } 139}; 140 141/** localStorage session functions **/ 142UMGECRM.clear_adhoc_block_states = function(block, ae_user) { 143 if(typeof Storage !== "undefined") { 144 if(typeof ae_user.data !== 'undefined' && typeof ae_user.data['ID'] !== 'undefined') { 145 var user_id = ae_user.data['ID']; 146 var adhoc_id = jQuery(block).attr('data-adhoc-id'); 147 return localStorage.removeItem('umgecrm-adhoc-state-' + user_id + '-' + adhoc_id); 148 } 149 } 150}; 151UMGECRM.get_adhoc_block_states = function(block, ae_user) { 152 if(typeof Storage !== "undefined") { 153 if(typeof ae_user.data !== 'undefined' && typeof ae_user.data['ID'] !== 'undefined') { 154 var user_id = ae_user.data['ID']; 155 var adhoc_id = jQuery(block).attr('data-adhoc-id'); 156 return JSON.parse(localStorage.getItem('umgecrm-adhoc-state-' + user_id + '-' + adhoc_id)); 157 } 158 } 159}; 160UMGECRM.set_adhoc_block_states = function (block, ae_user) { 161 if(typeof Storage !== "undefined") { 162 if(typeof ae_user.data !== 'undefined' && typeof ae_user.data['ID'] !== 'undefined') { 163 var adhoc_id = jQuery(block).attr('data-adhoc-id'); 164 var subs = {}; 165 jQuery('input[type="checkbox"]', jQuery(block)).each(function() { 166 var optin_id = jQuery(this).attr('data-optin-id'); 167 var checked = jQuery(this).is(':checked'); 168 subs[optin_id] = checked; 169 }); 170 171 var user_id = ae_user.data['ID']; 172 localStorage.setItem('umgecrm-adhoc-state-' + user_id + '-' + adhoc_id, JSON.stringify(subs)); 173 } 174 } 175}; 176 177 178UMGECRM.session_check_adhoc_exists = function(adhoc_id, ae_user) { 179 var exists = false;
180 if(typeof Storage !== "undefined") { 181 if(typeof ae_user.data !== 'undefined' && typeof ae_user.data['ID'] !== 'undefined') { 182 var user_id = ae_user.data['ID']; 183 exists = localStorage.getItem('umgecrm-adhoc-' + user_id + '-' + adhoc_id) ? true : false; 184 } 185 } 186 return exists; 187}; 188 189UMGECRM.session_set_adhoc = function(adhoc_id, ae_user) { 190 if(typeof Storage !== "undefined") { 191 if(typeof ae_user.data !== 'undefined' && typeof ae_user.data['ID'] !== 'undefined') { 192 var user_id = ae_user.data['ID']; 193 localStorage.setItem('umgecrm-adhoc-' + user_id + '-' + adhoc_id, true); 194 } 195 } 196}; 197 198 199 200/** Analytics Event Tracking **/ 201 202//function fired by AE Connect once custform form opt-ins are submitted 203// NB: we check for trackingDelegate.AEConnect first and don't overwrite it if it already exists as it may or may not be on the page already from other plugins 204var trackingDelegate = window.trackingDelegate || {}; 205if(typeof(trackingDelegate.AEConnect) == 'undefined') { 206 trackingDelegate.AEConnect = {}; 207} 208trackingDelegate.AEConnect.optinsUpdated = function(data) { 209 UMGECRM.trackEvent('optin_success_ae', data); 210}; 211 212UMGECRM.trackEvent = function(type, data) { 213 switch(type) { 214 //track opt-in for ae custom forms 215 case 'optin_success_ae': 216 switch(UMGECRM.sub_data.ecrm) { 217 case 'umgappi': 218 for(var sub_index in data.optins) { 219 var optin = data.optins[sub_index]; 220 if(optin.user_choice) { 221 var optins = UMGECRM.sub_data['ae'][data.cform_id]['subs']; 222 for(var i in optins) { 223 if(optins[i].optin_id == optin.optin_id) { 224 var sub_data = optins[i]; 225 var analytics_data = { 226 list_id: sub_data['umgapi-form-id'], 227 list_name: sub_data['umgapi-optin-ids'], 228 business_unit: sub_data['umgapi-form-id'] 229 }; 230 AEJSWP.debugOutput('Firing optin_success_ae event with data: ', analytics_data); 231 AEJSWP.executeFunctionByName(UMGECRM.analytics_tracking_delegate + '.optin_success', window, analytics_data); 232 } 233 } 234 } 235 } 236 break; 237 case 'exacttarget': 238 for(var sub_index in data.optins) { 239 var optin = data.optins[sub_index]; 240 if(optin.user_choice) { 241 var optins = UMGECRM.sub_data['ae'][data.cform_id]['subs']; 242 for(var i in optins) { 243 if(optins[i].optin_id == optin.optin_id) { 244 var sub_data = optins[i]; 245 var analytics_data = { 246 list_id: sub_data['et-list-id'], 247 list_name: sub_data['et-list-name'], 248 business_unit: sub_data['et-client-id'] 249 }; 250 AEJSWP.debugOutput('Firing optin_success_ae event with data: ', analytics_data); 251 AEJSWP.executeFunctionByName(UMGECRM.analytics_tracking_delegate + '.optin_success', window, analytics_data); 252 } 253 } 254 } 255 } 256 break; 257 case 'viceversa': 258 for(var sub_index in data.optins) { 259 var optin = data.optins[sub_index]; 260 if(optin.user_choice) { 261 var optins = UMGECRM.sub_data['ae'][data.cform_id]['subs']; 262 for(var i in optins) { 263 if(optins[i].optin_id == optin.optin_id) { 264 var sub_data = optins[i]; 265 var analytics_data = { 266 list_id: sub_data['vv-cf-optin-campaign-id'], 267 list_name: null, 268 business_unit: null 269 }; 270 AEJSWP.debugOutput('Firing optin_success_ae event with data: ', analytics_data); 271 AEJSWP.executeFunctionByName(UMGECRM.analytics_tracking_delegate + '.optin_success', window, analytics_data); 272 } 273 } 274 } 275 } 276 break; 277 case 'neolane': 278 for(var sub_index in data.optins) { 279 var optin = data.optins[sub_index]; 280 if(optin.user_choice) { 281 var optins = UMGECRM.sub_data['ae'][data.cform_id]['subs']; 282 for(var i in optins) { 283 if(optins[i].optin_id == optin.optin_id) { 284 var sub_data = optins[i]; 285 var list_id = null; 286 var list_name = null; 287 var business_unit = null; 288 if(typeof sub_data['nl-artist-id'] != 'undefined') { 289 list_id = sub_data['nl-artist-id']; 290 business_unit = sub_data['nl-source']; 291 list_name = sub_data['nl-label']; 292 } else if(typeof sub_data['nl-cf-optin-artist-id'] != 'undefined') { 293 list_id = sub_data['nl-cf-optin-artist-id']; 294 business_unit = sub_data['nl-cf-optin-source']; 295 list_name = sub_data['label']; 296 } 297 var analytics_data = { 298 list_id: list_id, 299 list_name: list_name, 300 business_unit: business_unit 301 }; 302 AEJSWP.debugOutput('Firing optin_success_ae event with data: ', analytics_data); 303 AEJSWP.executeFunctionByName(UMGECRM.analytics_tracking_delegate + '.optin_success', window, analytics_data); 304 } 305 } 306 } 307 } 308 break; 309 } 310 break; 311 //track opt-in for adhoc forms 312 case 'optin_success_adhoc': 313 switch(UMGECRM.sub_data.ecrm) { 314 case 'umgapi': 315 //loop through the opt-in choices 316 for(var sub_id in data.subs) { 317 var checked = data.subs[sub_id]; 318 if(checked) { 319 var optins = UMGECRM.sub_data['adhoc'][data.form_id]['subs']; 320 if(typeof optins[sub_id] !== 'undefined') { 321 var sub_data = optins[sub_id]; 322 var analytics_data = { 323 list_id: sub_data.list_id, 324 list_name: sub_data.list_name, 325 business_unit: sub_data.business_unit 326 }; 327 AEJSWP.debugOutput('Firing optin_success_adhoc event with data: ', analytics_data); 328 AEJSWP.executeFunctionByName(UMGECRM.analytics_tracking_delegate + '.optin_success', window, analytics_data); 329 } 330 } 331 } 332 break; 333 case 'exacttarget': 334 //loop through the opt-in choices 335 for(var sub_id in data.subs) { 336 var checked = data.subs[sub_id]; 337 if(checked) { 338 var optins = UMGECRM.sub_data['adhoc'][data.form_id]['subs']; 339 if(typeof optins[sub_id] !== 'undefined') { 340 var sub_data = optins[sub_id]; 341 var analytics_data = { 342 list_id: sub_data.list_id, 343 list_name: sub_data.list_name, 344 business_unit: sub_data.business_unit 345 }; 346 AEJSWP.debugOutput('Firing optin_success_adhoc event with data: ', analytics_data); 347 AEJSWP.executeFunctionByName(UMGECRM.analytics_tracking_delegate + '.optin_success', window, analytics_data); 348 } 349 } 350 } 351 break; 352 case 'viceversa': 353 var send_ecrm = false;
354 //check if ecrm call is being made if auto-post enabled or user ticked the opt-in box 355 if(UMGECRM.sub_data['adhoc'][data.form_id]['vv-auto-post-enabled']) { 356 send_ecrm = true; 357 } else if(typeof data.subs['vv-manual'] !== 'undefined') { 358 send_ecrm = true; 359 } 360 361 if(send_ecrm) { 362 var analytics_data = { 363 list_id: UMGECRM.sub_data['vv-campaign-id'], 364 list_name: null, 365 business_unit: null 366 }; 367 AEJSWP.debugOutput('Firing optin_success_adhoc event with data: ', analytics_data); 368 AEJSWP.executeFunctionByName(UMGECRM.analytics_tracking_delegate + '.optin_success', window, analytics_data); 369 } 370 break; 371 case 'neolane': 372 for(var sub_id in data.subs) { 373 var checked = data.subs[sub_id]; 374 if(checked) { 375 var optins = UMGECRM.sub_data['adhoc'][data.form_id]['subs']; 376 if(typeof optins[sub_id] !== 'undefined') { 377 var sub_data = optins[sub_id]; 378 var analytics_data = { 379 list_id: sub_data['nl-artist-id'], 380 list_name: sub_data['nl-label'], 381 business_unit: sub_data['nl-source'] 382 }; 383 AEJSWP.debugOutput('Firing optin_success_adhoc event with data: ', analytics_data); 384 AEJSWP.executeFunctionByName(UMGECRM.analytics_tracking_delegate + '.optin_success', window, analytics_data); 385 } 386 } 387 } 388 break; 389 } 390 391 break; 392 } 393};
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.