1( function () { 2 'use strict'; 3 4 var allowedSources = [ 5 'youtube', 'instagram', 'tiktok', 'newsletter', 'partner', 'google', 6 'bing', 'facebook', 'linkedin', 'wordpress', 'wpgoplugins', 'x', 'direct', 'other' 7 ]; 8 var allowedMedia = [ 9 'video', 'short', 'social', 'social_video', 'email', 'referral', 10 'organic', 'product_page', 'release_article', 'none' 11 ]; 12 13 if ( typeof window.gtag !== 'function' ) { 14 return; 15 } 16 17 function cleanDimension( value, maximumLength ) { 18 return String( value || '' ) 19 .toLowerCase() 20 .replace( /[^a-z0-9_-]/g, '-' ) 21 .replace( /-+/g, '-' ) 22 .replace( /^-|-$/g, '' ) 23 .slice( 0, maximumLength ); 24 } 25 26 function allowlisted( value, allowed, fallback ) { 27 return allowed.indexOf( value ) !== -1 ? value : fallback; 28 } 29 30 function campaignParameters() { 31 var parameters = new window.URLSearchParams( window.location.search ); 32 var source = cleanDimension( parameters.get( 'utm_source' ), 40 ); 33 var medium = cleanDimension( parameters.get( 'utm_medium' ), 40 ); 34 var campaign = cleanDimension( parameters.get( 'utm_campaign' ), 80 ); 35 var content = cleanDimension( parameters.get( 'utm_content' ), 80 ); 36 var result = {}; 37 38 if ( source ) { 39 result.campaign_source = allowlisted( source, allowedSources, 'other' ); 40 result.campaign_medium = allowlisted( medium, allowedMedia, 'other' ); 41 } 42 if ( campaign ) { 43 result.campaign_name = campaign; 44 } 45 if ( content ) { 46 result.campaign_content = content; 47 } 48 49 return result; 50 } 51 52 function productFromPath( path ) { 53 var match = String( path || '' ).match( /^\/(?:plugins|documentation)\/([a-z0-9-]+)(?:\/|$)/ ); 54 return match ? match[ 1 ] : ''; 55 } 56 57 function sourceSurface() { 58 var path = window.location.pathname; 59 60 if ( path === '/' ) { 61 return 'home'; 62 } 63 if ( /^\/plugins\//.test( path ) ) { 64 return 'product-page'; 65 } 66 if ( /^\/documentation\//.test( path ) ) { 67 return 'docs'; 68 } 69 if ( /^\/(?:blog|resources)(?:\/|$)/.test( path ) ) { 70 return 'article'; 71 } 72 73 return 'site'; 74 } 75 76 function baseParameters() { 77 return Object.assign( 78 { 79 page_location: window.location.origin + window.location.pathname, 80 source_surface: sourceSurface() 81 }, 82 campaignParameters() 83 ); 84 } 85 86 function sendEvent( eventName, parameters ) { 87 if ( window.wpgoAnalyticsAllowed !== true || 88 typeof window.wpgoAnalyticsHasConsent !== 'function' || ! window.wpgoAnalyticsHasConsent() ) { 89 return; 90 } 91 window.gtag( 'event', eventName, Object.assign( baseParameters(), parameters || {} ) ); 92 } 93 94 function classifyLink( link ) { 95 var explicitEvent = cleanDimension( link.getAttribute( 'data-wpgo-measure-event' ), 40 ); 96 var explicitTarget = cleanDimension( link.getAttribute( 'data-wpgo-measure-target' ), 40 ); 97 var url; 98 var match; 99 100 if ( explicitEvent ) { 101 return { eventName: explicitEvent, destinationType: explicitTarget, productSlug: '' }; 102 } 103 104 try { 105 url = new window.URL( link.href, window.location.href ); 106 } catch ( error ) { 107 return null; 108 } 109 110 match = url.pathname.match( /^\/plugins\/([a-z0-9-]+)(?:\/|$)/ ); 111 if ( /(^|\.)wordpress\.org$/i.test( url.hostname ) && match ) { 112 return { 113 eventName: 'free_install_click', 114 destinationType: 'install', 115 productSlug: match[ 1 ] === 'format-media-titles' ? 'seo-media-manager' : match[ 1 ] 116 }; 117 } 118 119 if ( url.protocol === 'https:' && url.hostname === 'demo.wpgoplugins.com' ) { 120 match = url.pathname.match( /^\/([a-z0-9-]+)(?:\/|$)/ ); 121 return match ? { eventName: 'demo_click', destinationType: 'demo', productSlug: match[ 1 ] } : null; 122 } 123 124 if ( url.origin !== window.location.origin ) { 125 return null; 126 } 127 match = url.pathname.match( /^\/plugins\/([a-z0-9-]+)(?:\/|$)/ ); 128 if ( match && url.hash === '#pricing' ) { 129 return { eventName: 'pricing_click', destinationType: 'pricing', productSlug: match[ 1 ] }; 130 } 131 132 match = url.pathname.match( /^\/documentation\/([a-z0-9-]+)(?:\/|$)/ ); 133 if ( match ) { 134 return { 135 eventName: 'docs_click', 136 destinationType: 'docs', 137 productSlug: match[ 1 ] 138 }; 139 } 140 141 if ( /(?:^|\/)demo(?:\/|$)/.test( url.pathname ) ) { 142 return { eventName: 'demo_click', destinationType: 'demo', productSlug: '' }; 143 } 144 145 if ( /^\/(?:contact-us|support)(?:\/|$)/.test( url.pathname ) ) { 146 return {
147 eventName: 'support_contact', 148 destinationType: 'support', 149 productSlug: productFromPath( window.location.pathname ) 150 }; 151 } 152 153 return null; 154 } 155 156 document.addEventListener( 'click', function ( event ) { 157 var link = event.target && typeof event.target.closest === 'function' 158 ? event.target.closest( 'a[href]' ) 159 : null; 160 var classification = link ? classifyLink( link ) : null; 161 162 if ( classification ) { 163 sendEvent( 164 classification.eventName, 165 { 166 product_slug: classification.productSlug || productFromPath( window.location.pathname ), 167 destination_type: classification.destinationType, 168 transport_type: 'beacon' 169 } 170 ); 171 } 172 } ); 173 174 document.addEventListener( 'wpgo:checkout-open', function ( event ) { 175 var detail = event && event.detail ? event.detail : {}; 176 177 sendEvent( 178 'checkout_open', 179 { 180 product_slug: cleanDimension( detail.product, 64 ), 181 destination_type: 'checkout', 182 transport_type: 'beacon' 183 } 184 ); 185 } ); 186 187 var pageViewSent = false; 188 function sendPageView() { 189 if ( ! pageViewSent && window.wpgoAnalyticsAllowed === true && window.wpgoAnalyticsHasConsent() ) { 190 pageViewSent = true; 191 sendEvent( 'page_view', { 192 page_title: window.location.pathname, 193 product_slug: productFromPath( window.location.pathname ) 194 } ); 195 } 196 } 197 document.addEventListener( 'wpgo:analytics-consent', sendPageView ); 198 sendPageView(); 199}() );
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.