1/** 2 * Permutive Identifier. 3 * 4 * Passes additional user identities to Permutive with `permutive.identify`. 5 * 6 * @link https://developer.permutive.com/page/audience-connector#3-identities 7 * 8 * @package tmbi-permutive 9 */ 10 11/* global wp, tmbi, queryUtils */ 12 13var Permutive_Identifier = { 14 /** 15 * Get all identities for the user and pass them to `permutive.identify`. 16 */ 17 identify: function() { 18 var identities = Permutive_Identifier.get_user_identities(); 19 20 if ( ! identities.length ) { 21 return; 22 } 23 24 permutive.identify( identities ); 25 }, 26 /** 27 * Get all identities for the current user. 28 * 29 * @returns {[]} 30 */ 31 get_user_identities: function() { 32 var identities = []; 33 var identity_callbacks = { 34 'email_sha1': this.get_email_hash, 35 'TMCM': () => (typeof window.getSessionGUID === 'function' ? window.getSessionGUID() : ''), 36 'email_sha256':this.get_email_hash_sha256 37 }; 38 39 for ( var id_tag in identity_callbacks ) { 40 if ( ! identity_callbacks.hasOwnProperty( id_tag ) ) { 41 continue; 42 } 43 var id = identity_callbacks[ id_tag ](); 44 if ( ! id ) { 45 continue; 46 } 47 identities.push( 48 { 49 'id': id, 50 'tag': id_tag, 51 } 52 ); 53 } 54 55 return identities; 56 }, 57 /** 58 * Get the SHA-1 email hash for the current user. 59 * 60 * @returns {string} 61 */ 62 get_email_hash: function() { 63 if ( 'undefined' === typeof queryUtils ) { 64 return ''; 65 } 66 67 var ehid = queryUtils.getQueryParam( 'ehid' ); 68 69 if ( ehid ) { 70 document.cookie = 'Ehid=' + ehid + ';path=/;domain=.' + location.host; 71 return ehid; 72 } 73 74 if ( 'undefined' !== typeof getCookie && getCookie( 'Ehid' ) ) { 75 return getCookie( 'Ehid' ); 76 } 77 78 return ''; 79 }, 80 /** 81 * Get the internal GUID for the current user. 82 * 83 * @todo ideally this should be using the TMBI visitors API, but it loads in the footer and this script runs in the header. load visitors in head instead? 84 * 85 * @return {string} 86 */ 87 get_internal_user_id: function() { 88 if ( 'undefined' === typeof getCookie ) { 89 return ''; 90 } 91 92 return getCookie( 'ID' ); 93 }, 94 /** 95 * Get the SHA-256 email hash for the current user from local storage. 96 * 97 * @returns {string} 98 */ 99 get_email_hash_sha256: function() { 100 101 if(null === localStorage.getItem("user")){ 102 return ''; 103 } 104 105 var user = JSON.parse(localStorage.getItem("user")); 106 107 if ( 'undefined' === typeof user['email'] ) { 108 return ''; 109 } 110 111 return user['email']; 112 }, 113}; 114 115wp.hooks.addAction( 116 'permutive_init', 117 'tmbi/permutive/identifier', 118 Permutive_Identifier.identify 119); 120 121// Add tmcm value to permutive page view data WPDT-12709. 122function addPermutivePageData( permutive_page_data ) { 123 if ( window.getSessionGUID ) { 124 permutive_page_data.tmcm = getSessionGUID(); 125 } 126 return permutive_page_data; 127} 128wp.hooks.addFilter( 'permutive_page_data', 'permutive_data', addPermutivePageData ); 129 130var permutive_page_data = wp.hooks.applyFilters( 'permutive_page_data', permutivePageSchema ); 131 132wp.hooks.doAction('permutive_init'); 133 134permutive.addon( 'web', { 135 "page": permutive_page_data 136} );
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.