Seo

Managing SEO in WordPress | WordPress.com Support

[] Managing SEO in WordPress | WordPress.com Support res.json() ); } function removeLink( selector, condition ) { document.querySelectorAll( selector ).forEach( element => { const parent = element.parentNode; const parentTagName = parent.tagName.toLowerCase(); if ( condition ) { (parentTagName === ‘li’ ? parent : element).remove(); } }); } /** * Checks if the given data pertains to the specified region or country * @param {string} key – The key to check in the data * @param {string} name – The region or country name to check for * @param {object} data – The geolocation data * @returns {boolean} – True if the data pertains to the specified region or country */ function pertainsTo( key, name, data ) { if ( data && data[ key ] && name ) { return data[ key ].toLowerCase() === name.toLowerCase(); } return false; } fetchGeoData().then(data => { const isFCCA = pertainsTo( ‘country_long’, ‘germany’, data ); removeLink( FCCA_LINK_SELECTOR, ! isFCCA ); }); }); ]]> WordPress.com, WooCommerce, Jetpack, Simplenote, Longreads, VaultPress, Akismet, Gravatar, Crowdsignal, Cloudup, and more. We believe in making the web a better place, and we believe in Open Source. The vast majority of our work is available under the GPL.”,”logo”:{“@type”:”ImageObject”,”@id”:”https://automattic.com/#logo”,”url”:”https://automattic.com/wp-content/themes/a8c/automattic-2011/images/automattic-logo-2x.png”,”width”:552,”height”:60,”caption”:”Automattic”},”image”:{“@id”:”https://automattic.com/#logo”},”address”:{“@type”:”PostalAddress”,”streetAddress”:”60 29th Street #343″,”addressLocality”:”San Francisco”,”addressRegion”:”CA”,”postalCode”:”94110″,”addressCountry”:”US”},”founder”:{“@type”:”Person”,”@id”:”https://wordpress.com/schema.org/author/5#person”,”name”:”Matt Mullenweg”,”description”:”In 2002 I started contributing to Open Source software, and life has just gotten better from there. Co-founder of WordPress, founder Automattic.”,”image”:{“@type”:”ImageObject”,”@id”:”https://wordpress.com/schema.org/author/5#personimage”,”url”:”https://secure.gravatar.com/avatar/767fc9c115a1b989744c755db47feb60?s=96&d=mm&r=g”,”width”:96,”height”:96,”caption”:”Matt Mullenweg”}},”numberOfEmployees”:1915,”sameAs”:[“https://twitter.com/automattic”,”https://www.facebook.com/AutomatticInc”,”https://www.linkedin.com/company/automattic/”,”https://en.wikipedia.org/wiki/Automattic”,”https://www.youtube.com/c/automattic”],”subOrganization”:{“@id”:”https://wordpress.com/#organization”}},{“@type”:”Organization”,”@id”:”https://wordpress.com/#organization”,”url”:”https://wordpress.com/”,”name”:”WordPress.com”,”legalName”:”Automattic, Inc.”,”foundingDate”:”2005-08-01″,”slogan”:”Build a website, build a movement.”,”description”:”Create a free website or build a blog with ease on WordPress.com. Dozens of free, customizable, mobile-ready designs and themes. Free hosting and support.”,”logo”:{“@type”:”ImageObject”,”@id”:”https://wordpress.com/#logo”,”url”:”https://s0.wp.com/home.logged-out/images/wpcom-a-website-that-can.jpg”,”width”:1024,”height”:512,”caption”:”WordPress.com”},”image”:{“@id”:”https://wordpress.com/#logo”},”address”:{“@type”:”PostalAddress”,”streetAddress”:”60 29th Street #343″,”addressLocality”:”San Francisco”,”addressRegion”:”CA”,”postalCode”:”94110″,”addressCountry”:”US”},”founder”:{“@type”:”Person”,”@id”:”https://wordpress.com/schema.org/author/5#person”,”name”:”Matt Mullenweg”,”description”:”In 2002 I started contributing to Open Source software, and life has just gotten better from there. Co-founder of WordPress, founder Automattic.”,”image”:{“@type”:”ImageObject”,”@id”:”https://wordpress.com/schema.org/author/5#personimage”,”url”:”https://secure.gravatar.com/avatar/767fc9c115a1b989744c755db47feb60?s=96&d=mm&r=g”,”width”:96,”height”:96,”caption”:”Matt Mullenweg”}},”numberOfEmployees”:1915,”sameAs”:[“https://twitter.com/wordpressdotcom”,”https://www.facebook.com/WordPresscom”,”https://www.instagram.com/wordpressdotcom/”,”https://www.linkedin.com/company/wordpress”,”https://www.youtube.com/WordPressdotcom”,”https://www.pinterest.com/wordpressdotcom/”,”https://en.wikipedia.org/wiki/WordPress.com”],”parentOrganization”:{“@id”:”https://automattic.com/#organization”}},{“@type”:”WebSite”,”@id”:”https://wordpress.com/support/#website”,”url”:”https://wordpress.com/support/”,”name”:”WordPress.com Support”,”description”:”WordPress.com Support”,”potentialAction”:{“@type”:”SearchAction”,”target”:”https://wordpress.com/support/search/{search_term_string}/”,”query-input”:”required name=search_term_string”},”publisher”:{“@id”:”https://wordpress.com/#organization”}},{“@type”:”BreadcrumbList”,”@id”:”https://wordpress.com/support/seo/#breadcrumbs”,”itemListElement”:[{“@type”:”ListItem”,”position”:0,”item”:{“@type”:”WebSite”,”@id”:”https://wordpress.com/support/#website-breadcrumb”,”url”:”https://wordpress.com/support/”,”name”:”Home”}},{“@type”:”ListItem”,”position”:1,”item”:{“@type”:”CollectionPage”,”@id”:”https://wordpress.com/support/category/grow-your-audience/get-found-in-search-engines/#term-breadcrumb”,”url”:”https://wordpress.com/support/category/grow-your-audience/get-found-in-search-engines/”,”name”:”Get Found in Search Engines”}},{“@type”:”ListItem”,”position”:2,”item”:{“@type”:”WebPage”,”@id”:”https://wordpress.com/support/seo/#webpage-breadcrumb”,”url”:”https://wordpress.com/support/seo/”,”name”:”Managing SEO in WordPress | WordPress.com Support”}}]},{“@type”:”ImageObject”,”@id”:”https://wordpress.com/support/seo/#primaryimage”,”url”:”https://en-support.files.wordpress.com/2023/08/privacy-settings-public.png”,”width”:1418,”height”:678,”caption”:”Managing SEO in WordPress | WordPress.com Support”},{“@type”:”WebPage”,”@id”:”https://wordpress.com/support/seo/#webpage”,”url”:”https://wordpress.com/support/seo/”,”name”:”Managing SEO in WordPress | WordPress.com Support”,”description”:”WordPress.com Support”,”inLanguage”:”en”,”isPartOf”:{“@id”:”https://wordpress.com/support/#website”},”primaryImageOfPage”:{“@id”:”https://wordpress.com/support/seo/#primaryimage”},”breadcrumb”:{“@id”:”https://wordpress.com/support/seo/#breadcrumbs”},”publisher”:{“@id”:”https://wordpress.com/#organization”},”datePublished”:”2016-08-21T02:54:51+0000″,”dateModified”:”2024-03-22T17:42:17+0000″},{“@type”:”Article”,”@id”:”https://wordpress.com/support/seo/#article”,”headline”:”Managing SEO in WordPress | WordPress.com Support”,”commentCount”:0,”keywords”:”get found in search engines,grow your audience”,”datePublished”:”2016-08-21T02:54:51+0000″,”dateModified”:”2024-03-22T17:42:17+0000″,”mainEntityOfPage”:{“@id”:”https://wordpress.com/support/seo/#webpage”},”isPartOf”:{“@id”:”https://wordpress.com/support/seo/#webpage”},”image”:{“@id”:”https://wordpress.com/support/seo/#primaryimage”},”publisher”:{“@id”:”https://wordpress.com/#organization”},”author”:{“@id”:”https://wordpress.com/#organization”}}]} ]]>

Other languagesالعربيةDeutschEspañolFrançaisעִבְרִיתBahasa IndonesiaItaliano日本語한국어NederlandsPortuguês do BrasilРусскийSvenskaTürkçe简体中文繁體中文

Your WordPress.com website is optimized for search engines by default. However, there’s more that you can do as a website owner to influence how people find you through search engines like Google.

SEO stands for Search Engine Optimization. It refers to techniques you can use to help ensure that your site ranks high in the results of search engines such as Google and Bing.

To ensure your website gets indexed in search engines, review your site’s Privacy Settings at Settings → General (or HostingSettings if using WP-Admin). To allow search engines to index your site, your site must be set to public, and the checkbox for Discourage search engines from indexing this site should not be checked.

Privacy settings, with Public as the selected option and the Site settings required to appear in search engines.

A public site ensures your site can be seen by search engines, but keep in mind that it can take Google and other search engines between four to six weeks to discover a new website.

Every website owner wants their website to appear at the top of search results. However, the processes that control this are handled by each search engine, and they are always changing. The tips and resources in the rest of this guide will help you to improve your SEO.

Improve Your Search Engine Rank

There is a difference between being indexed by search engines (appearing somewhere in the results) and having a high ranking (appearing on the first page of results.) Ranking in search engines means the search engine has decided your website closely matches what the person is searching for. Search engines use a variety of criteria to determine if a site should rank high for a specific search request.

Ranking higher in Google and other search engines can take time. Here are some tips you can use to help influence the process:

  • Research your keywords: Figure out what keywords you want to come up in searches for. For example, if your site is about boating, you might want to show up for terms like “boats,” “sailing,” and “crew.” Work these keywords naturally into your post titles, headings, content, and URLs.
  • Describe your images: A search engine can’t “read” an image, but it can read what an image shows if you provide it with descriptive image alt text.
  • Post new content regularly: The more you post, the higher your search ranking. Google likes sites that update frequently. You don’t necessarily need to post every day or every week – find a cadence that works for you and stay consistent.
  • Share your site: Automatically share your posts to social media when you publish, and reach a larger audience. The more organic traffic your site gets, the better it looks to search engines.
  • Verify your site with search engines: Verify your site with Google Search Console and other search engines by following the steps in this guide. This step isn’t necessary for your site to be indexed, but it can speed up the process and give you useful insights to learn from.

There is no setting, plugin, service, or person that can guarantee your site shows up first in search rankings. If someone is trying to sell you SEO services that promise fast results, they may be trying to drive fake traffic to your site. This can penalize your site’s SEO and lock you out of participating in ad programs.

This section of the guide applies to sites with the WordPress.com Creator and Entrepreneur plans, and the legacy Pro plan. For sites on the free, Starter, and Explorer plans, upgrade your plan to access this feature.

In addition to the above techniques, our higher-level plans include additional SEO tools you can learn about here.

You do not need a plugin-enabled plan for your site to be indexed and ranked in search engines. You do not need any particular plugin, either. However, plugins can provide useful tools to fine-tune your search results and optimize your site’s ranking.

If your site has plugins enabled, add a custom domain name for your site to be indexed by Google. The.wpcomstaging.com domain will not be indexed by search engines.

Yoast SEO is a powerful plugin that can help you optimize your website for search engines. It’s easy to use and provides many features that can help you improve your website’s visibility. Some of the benefits of using Yoast SEO include optimizing your content for specific keywords, creating custom meta descriptions and titles, and analyzing your website’s performance. Yoast SEO also has a paid Premium version that offers additional features such as internal linking suggestions, content insights, and a redirect manager.

If you install an SEO plugin, it will replace the built-in tools provided by your plan. Solutions such as Yoast Premium offer an alternative suite of SEO tools for your site. Installing more than one SEO plugin at a time is not recommended, as multiple plugins with the same function can cause conflicts or errors.

Join Our Free SEO Course

Understanding search engine optimization (SEO) is valuable for anyone looking to improve their site or blog for both search engines and humans. This course will give you a solid foundation of what you can do to ensure people have the best chance to find your content when they search online.

Watch our recorded webinar that will show you how to do effective keyword research for your site’s SEO:

Frequently Asked Questions

For the sake of brevity, the following questions all refer to Google. However, the same answers apply to all search engines.

Why isn’t my site showing up on Google?

Search engines can take 4-6 weeks or more to show any newly created sites.

Ensure your site’s privacy settings are set to Public, with the option “Do not allow search engines to index my site” not selected.

While not necessary to be included in Google’s index, connecting your site to Google’s Search Console can help Google include your site more quickly.

Why is my site’s information in search results incomplete or incorrect?

If you make changes to your site, the site previews provided by Google may take some time to update (anywhere from a few days to a few weeks.)

It’s up to Google to decide what information to display as a search preview. You can try adding an excerpt to your post or page and updating your site title and tagline, but what is displayed is ultimately decided by Google.

Can you analyze my site’s SEO?

There are many tools you can use to audit your site’s SEO, including Google Search Console and Yoast SEO. WordPress.com support cannot assist with processing these reports. WordPress.com is optimized for SEO on a technical level, and you, as the site owner, can optimize your site’s content. For help with that, we encourage you to follow the tips on this page as well as the resources provided by the third-party tool you have used to check your site’s SEO.

What is this error in my site description on Google?

“A description for this result is not available because of this site’s robots.txt – learn more”

If you had your site visibility set to Private for a long time and just changed it to Public, you would not see the description of your site in Google right away. Instead, you will see the above message.

Allow some time for Google to crawl and index your site, and the description of it will eventually update on its own.

Microsoft’s Bing search engine shows “We would like to show you a description here but the site won’t allow us.” under your site’s URL in these cases.

“No Information Available for This Page”

If search engines index your site before you add a meta description, they may display the message “No information available for this page” instead of a description.

Make sure you update your meta description. Then, allow search engines two to four weeks to re-index your site and display the new information.

How do I edit my robots.txt file?

By default, every website hosted on WordPress.com has its own robots.txt file that search engines will pick up. You have a few options if you need to add additional customizations to your robots.txt file.

This section of the guide applies to sites with the WordPress.com Creator and Entrepreneur plans, and the legacy Pro plan. For sites on the free, Starter, and Explorer plans, upgrade your plan to access this feature.

  • You can create a custom robots.txt file and upload it to your root directory via SFTP.
  • You can use a plugin designed to edit your robots.txt file, like Robots.txt Editor.
  • Plugins designed to improve SEO (like Yoast or Rank Math SEO) also include settings for editing your robots.txt file.

Remember, most plugins are developed by third-party developers. They will be more familiar with installing, configuring, and troubleshooting issues with their plugin. Any good plugin will have a method for you to contact them for help.

Was this guide helpful for you?

What can we do to make this guide more helpful?

Copied to clipboard!

Learn more, including how to control cookies.”,”v2Text”:”As an open source company, we take your privacy seriously and want to be as transparent as possible. So: We use cookies to collect some personal data from you (like your browsing data, IP addresses, and other unique identifiers). Some of these cookies we absolutely need in order to make things work, and others you can choose in order to optimize your experience while using our site and services.”,”v2OptionsText”:”Your privacy is critically important to us. We and our partners use, store, and process your personal data to optimize: our website such as by improving security or conducting analytics, marketing activities to help deliver relevant marketing or content, and your user experience such as by remembering your account name, language settings, or cart information, where applicable. You can customize your cookie settings below. Learn more in our Privacy Policy and Cookie Policy.”,”v2EssentialOptionHeading”:”Required”,”v2EssentialOptionText”:”These cookies are essential for our websites and services to perform basic functions and are necessary for us to operate certain features, like allowing registered users to authenticate and perform account-related functions, storing preferences set by users (like account name, language, and location), and ensuring our services operate properly.”,”v2AnalyticsOptionHeading”:”Analytics”,”v2AnalyticsOptionText”:”These cookies allow us to optimize performance by collecting information on how users interact with our websites.”,”v2AdvertisingOptionHeading”:”Advertising”,”v2AdvertisingOptionText”:”We and our advertising partners set these cookies to provide you with relevant content and to understand that contentu2019s effectiveness.”,”v1ButtonText”:”Got It!”,”v2CustomizeButtonText”:”Customize”,”v2AcceptAllButtonText”:”Accept all”,”v2AcceptSelectionButtonText”:”Accept selection”,”hiddenConsents”:[],”isLoggedIn”:false},”doNotSellDialog”:{“contactEmailAddress”:”privacypolicyupdates@automattic.com”},”adminAnalytics”:”analytics-wpcom-admin.php”,”fireAnalyticsOptions”:[]}; }; if ( window.defQueue && defQueue.isLOHP && defQueue.isLOHP === 2020 ) { defQueue.items.push( setupAnalytics ); } else { setupAnalytics(); } } )(); ]]>

{ let { target: element } = event; let foundElement = null; while ( element && !foundElement ) { for ( const selector of selectors ) { if ( element.matches( selector ) ) { foundElement = element; break; } } element = element.parentElement; } return foundElement; } /** * Establish the closest parent from an element matching * a given list of selectors. Selectors can be css classes, IDs, * element types, etc. (e.g. ‘.my-class’, ‘#my-id’, ‘div’, etc.) */ const getClosestMatchingAncestor = ( event, selectors ) => { let { target: element } = event; let foundElement; for ( const selector of selectors ) { foundElement = element.closest( selector ); if ( foundElement ) { break; } } return foundElement; } /** * Main function to setup analytics. */ const setupAnalytics = () => { /** * Returns the current page path. */ function getCurrentPagePath( pathname = ” ) { return ( pathname || window.location.pathname ).replace( /^/|/$/g, ” ); } /** * Returns the current page name. */ function getCurrentPageName( pathname = ” ) { return getCurrentPagePath( pathname ).replace( getLocaleInPagePathRegExp(), ” ); } /** * Returns the current page locale. */ function getCurrentPageLocale() { const currentPagePath = getLocaleInPagePathRegExp().exec( getCurrentPagePath() ); return getCurrentPagePath !== null && getCurrentPagePath.length === 2 ? getCurrentPagePath[1] : ”; } /** * Helper function to extract locale from page path. */ function getLocaleInPagePathRegExp() { return /^(af|als|am|an|ar|arc|as|ast|av|ay|az|ba|bel|bg|bm|bn|bo|br|bs|ca|ce|ckb|cs|csb|cv|cy|da|de|dv|dz|el|el-po|en|en-gb|eo|es|es-mx|et|eu|fa|fi|fo|fr|fr-be|fr-ca|fr-ch|fur|fy|ga|gd|gl|gn|gu|he|hi|hr|hu|hy|ia|id|ii|ilo|is|it|ja|ka|kir|km|kn|ko|kk|ks|kv|la|li|lo|lv|lt|mk|ml|mwl|mn|mr|ms|mya|nah|nap|ne|nds|nl|nn|nb|non|nv|oci|or|os|pa|pl|ps|pt|pt-br|qu|ro|ru|rup|sc|si|sk|skr|sl|snd|so|sq|sr|su|sv|ta|te|th|tl|tir|tr|tt|ty|udm|ug|uk|ur|uz|vec|vi|wa|xal|yi|yo|za|zh-cn|zh-hk|zh-tw)(?:/|$)/; } /** * Returns the config for WPcom analytics. Sets various event props * used in tracking, e.g. locale, page path, etc. Mainly used for Tracks * event props. */ function getWPCOMAnalyticsDefaultConfig() { const currentGenericPageName = null; const cannonicalPath = “/support/seo/”; return { // Current page props. currentPagePath: getCurrentPagePath(), currentPageName: getCurrentPageName(), currentGenericPageName: currentGenericPageName ?? getCurrentPageName( cannonicalPath ), currentPageLocale: getCurrentPageLocale(), // Page variation props. pageVariation: ”, pagePersonalVariation: ”, // Current user props. currentUserIdHash: “”, currentUserIdHashShort: “”, currentUserEmailHash: “”, // Other misc. props. isHomepage: false, affiliateJSVersion: “1716355472”, } } // When a8c-analytics:loaded is fired, start main event handling. document.addEventListener( ‘a8c-analytics:loaded’, () => { const cb = window.a8cAnalytics.cb; const kit = window.a8cAnalytics.kit; const config = getWPCOMAnalyticsDefaultConfig(); const configOptions = window.a8cAnalyticsConfig.fireAnalyticsOptions; // Extend config with any custom props. Object.assign( window.a8cAnalyticsConfig, config ); // Backcompat. for `lpName` and `lpVariation` config properties. config.currentPageName = ! configOptions.currentPageName && ‘logged-out-homepage’ === configOptions.lpName ? configOptions.lpName : config.currentPageName; config.currentPageName = ! configOptions.currentPageName && ‘logged-out-app-promo’ === configOptions.lpName ? configOptions.lpName : config.currentPageName; // Backcompat. for `lpPersonalVariation` config property. config.pageVariation = ! configOptions.pageVariation && configOptions.lpVariation ? configOptions.lpVariation : config.pageVariation; config.pagePersonalVariation = ! configOptions.pagePersonalVariation && configOptions.lpPersonalVariation ? configOptions.lpPersonalVariation : config.pagePersonalVariation; /** * Applies linkers, e.g. for “forwarding” certain URL parameters between WordPress.com * and other properties (e.g. Jetpack.com). Used for affiliate tracking, coupons, etc. */ const applyLinkers = () => { kit.linkQueryVars( [ { includeRegExps: [ /^(?:[^/]+.)?(?:wordpress|jetpack|woocommerce|crowdsignal|wpjobmanager).com(?:/|$)/i, ], linkQueryVars: [ ‘aff’, ‘affiliate’, ‘cid’, // Aff campaign ID. ‘sid’, // Aff sub ID. ‘irclickid’ // Impact Affiliate Click ID ], }, { includeRegExps: [ /^(?:[^/]+.)?(?:wordpress|jetpack).com(?:/|$)/i, ], linkQueryVars: [ ‘coupon’, ], }, ] ); } /** * Handles currencies. Gets the currency value from cookies, and sets the currency * if the cookie is not present. Can also be overridden by setting the `currency` URL * paramter. */ const fireCurrencyHandlers = () => { let currency = kit.getQueryVar( ‘currency’ ) || ”; if ( ! currency && ‘amex-business-in’ === config.currentPageName ) { currency = ‘USD’; // Special case for this LP. } if ( currency ) { kit.docCookies.setItem( ‘landingpage_currency’, currency, 31536000, ‘/’, ‘.rootDomain’ ); } }; /** * Fires the `wpcom_page_view` Tracks event. */ const fireTracks = () => { const props = Object.assign( {}, kit.getQueryVars( ”, kit.QUERY_PARAMS ), { // Page props. path: config.currentPagePath, name: config.currentPageName, locale: config.currentPageLocale, variation: config.pageVariation, personal_variation: config.pagePersonalVariation, // Back compat. LP props. lp_name: config.currentGenericPageName, lp_variation: config.pageVariation, lp_personal_variation: config.pagePersonalVariation, } ); window._tkq.push( [ ‘recordEvent’, ‘wpcom_page_view’, props ] ); }; function fireRedditAdvertisingPixel() { !function(w,d){if(!w.rdt){var p=w.rdt=function(){p.sendEvent?p.sendEvent.apply(p,arguments):p.callQueue.push(arguments)};p.callQueue=[];var t=d.createElement(“script”);t.src=”https://www.redditstatic.com/ads/pixel.js”,t.async=!0;var s=d.getElementsByTagName(“script”)[0];s.parentNode.insertBefore(t,s)}}(window,document); rdt(‘init’,’a2_ehx23cq176s3′); rdt(‘track’, ‘PageVisit’); } /** * Handles the referral tracking. */ const fireAffiliateReferrals = () => { kit.attachScriptElement( ‘https://s1.wp.com/wp-content/themes/h4/landing/marketing/js/affiliate-referrals.js?v=’ + config.affiliateJSVersion ); }; /** * Loads the Google Ads gtag. */ const loadGoogleAdsGtag = () => { kit.loadGtag( ‘AW-946162814’ ); } /** * Loads and fires the Google Analytics 4. */ const fireGoogleAnalyticsFour = () => { const gtagOptions = { ‘anonymize_ip’: true, ‘use_amp_client_id’: true }; kit.loadGtag( ‘G-1H4VG5F5JF’, gtagOptions ); } const fireParsely = ( trackingId ) => { kit.loadParselyTracker( trackingId ); } const fireHotJar = () => { if ( ! kit.pertainsToSTS() ) { kit.fireHotjar( 227769 ); } } /** * Loads and fires the Facebook Pixel. */ const fireFacebook = () => { kit.loadFacebook(); fbq( ‘init’, ‘823166884443641’ ); fbq( ‘track’, ‘PageView’ ); } /** * Loads and fires Microsoft Clarity */ const fireMicrosoftClarity = () => { if ( window.clarity ) { return; } // Needs to be set prior to loading the external script. window.clarity = window.clarity || function () { ( window.clarity.q = window.clarity.q || [] ).push( arguments ); }; const clarityScript = kit.attachScriptElement( ‘https://www.clarity.ms/tag/j0cc1i1dba’ ); document.body.appendChild( clarityScript ); }; const fireImpactAffiliate = () => { kit.loadImpactAffiliate( config.currentUserIdHash, config.currentUserEmailHash ); } /** * Handles scroll percentage tracking. */ const trackScrollPercentage = () => { const scrollPosition = window.pageYOffset; const pageHeight = document.body.scrollHeight – window.innerHeight; const scrollProgress = ( scrollPosition / pageHeight ) * 100; // Check if the user has scrolled to 25%, 50%, 75%, or 100% of the page if ( scrollProgress >= 25 && scrollProgress = 50 && scrollProgress = 75 && scrollProgress = 100 ) { dispatchScrollCustomEvent( 100 ) } } /** * Dispatches a custom event with the scroll percentage. */ const dispatchScrollCustomEvent = ( scrollPercentage ) => { const event = new CustomEvent( `PageScrollPercentage${scrollPercentage}`, { detail: scrollPercentage } ); window.dispatchEvent(event); } /** * Handles the scroll tracking callback. E.g. firing Tracks and GA events. */ const scrollTrackingCallback = ( event ) => { const { detail: scrollPercentage } = event; const trackingProps = {}; // Event props. trackingProps.percent = event.detail ?? 0; trackingProps.path = config.currentPagePath || ”; trackingProps.name = config.currentPageName || ”; trackingProps.locale = config.currentPageLocale || ”; trackingProps.variation = config.pageVariation || ”; trackingProps.personal_variation = config.pagePersonalVariation || ”; trackingProps.lp_name = config.currentGenericPageName || ”; trackingProps.lp_variation = config.pageVariation || ”; trackingProps.lp_personal_variation = config.pagePersonalVariation || ”; tracksAnalyticsScrollEvent( trackingProps ); } /** * Dispatches a Tracks event for page scroll. */ const tracksAnalyticsScrollEvent = ( trackingProps ) => { window._tkq.push( [ ‘recordEvent’, ‘wpcom_page_scroll’, trackingProps ] ); } // Call the trackScrollProgress function every time the user scrolls window.addEventListener( ‘scroll’, trackScrollPercentage ); // Listen to events for specific scroll percentages, each event is only acted upon once. window.addEventListener( ‘PageScrollPercentage25’, scrollTrackingCallback, { once: true } ) window.addEventListener( ‘PageScrollPercentage50’, scrollTrackingCallback, { once: true } ) window.addEventListener( ‘PageScrollPercentage75’, scrollTrackingCallback, { once: true } ) window.addEventListener( ‘PageScrollPercentage100’, scrollTrackingCallback, { once: true } ) /** * Handles click tracking for certain elements in Tracks and GA. */ const setupTracksGAClickTracking = () => { document.querySelector( ‘body’ ).addEventListener( ‘click’, ( event ) => { // We only care about clicks on certain elements. if ( event.target.matches( ‘a, button, .click-tracking-enable’ ) ) { const { target: clickEventTarget } = event; // Initialize eventProps object with some defaults. const eventProps = {}; eventProps.path = config.currentPagePath || ”; eventProps.name = config.currentPageName || ”; eventProps.lp_name = config.currentGenericPageName || ”; eventProps.locale = config.currentPageLocale || ”; eventProps.variation = config.pageVariation || ”; eventProps.personal_variation = config.pagePersonalVariation || ”; // Identify farthest and closest parent element. const selectors = [ ‘.wpcom-masterbar.wpcom-header’, ‘.lp-block’, ‘.lpc’, ‘.lp-module’, ‘section’, ‘post’, ‘article’ ]; const section = getLastMatchingAncestor( event, selectors ); const container = getClosestMatchingAncestor( event, selectors ); // Get class name and ID for container and add to props. eventProps.container_id = container ? container.getAttribute( ‘id’ ) : ”; eventProps.container_class = container ? container.getAttribute( ‘class’ ) : ”; eventProps.container = eventProps.container_id || eventProps.container_class; // What type of element have we clicked? eventProps.is_cta = clickEventTarget.matches( ‘is-cta’ ) ?? false; eventProps.is_in_header_nav = clickEventTarget.classList.contains(‘x-nav-link’) || clickEventTarget.classList.contains(‘x-dropdown-link’) || clickEventTarget.classList.contains(‘x-menu-link’) || section === ‘lpc-header-nav’ || section === ‘wpcom-masterbar.wpcom-header’; const isClickedElementButton = clickEventTarget.classList.contains(‘lpc-button’) || clickEventTarget.classList.contains(‘button’) || clickEventTarget.classList.contains(‘wp-block-button__link’); const isParentElementButton = clickEventTarget.parentElement && (clickEventTarget.parentElement.classList.contains(‘lpc-button’) || clickEventTarget.parentElement.classList.contains(‘button’) || clickEventTarget.parentElement.classList.contains(‘wp-block-button__link’)); eventProps.is_button = isClickedElementButton || isParentElementButton; // Link data. eventProps.href = clickEventTarget.getAttribute( ‘href’ ) || ”; eventProps.target = clickEventTarget.getAttribute( ‘target’ ) || ”; eventProps.text = clickEventTarget.innerText || ”; eventProps.use_beacon = true; // Emit tracking event in Tracks and GA. window._tkq.push( [ ‘recordEvent’, ‘wpcom_link_click’, eventProps ] ); // TODO: Implement a click delay on navigation links and CTA buttons to improve data integrity. // if ( props.is_in_header_nav || props.is_cta || props.is_button ) { // if ( props.href && 0 !== props.href.indexOf( ‘#’ ) && -1 !== [ ”, ‘_top’, ‘_self’ ].indexOf( props.target ) ) { // event.preventDefault(); // Allow time for trackers to record the click. // setTimeout( function() { // document.location = props.href; // }, 300 ); // } // } } }); } /** * Add cookie and stats tracking for the Landpack language picker. */ const setupLocaleChangeTracking = () => { function createLocaleCookie( locale ) { const cookieDomain = ‘.wordpress.com’; const cookieName = ‘wpcom_locale’; const date = new Date(); date.setTime( date.getTime() + ( 5 * 365 * 24 * 60 * 60 * 1000 ) ); const expires = ” expires=” + date.toGMTString(); document.cookie = cookieName + ‘=’ + locale + ‘;’ + expires +’; path=/; domain=’ + cookieDomain; } function createStatsRequest( locale, href ) { const languageChangeStat = new Image(); languageChangeStat.onload = () => window.location.href = href; languageChangeStat.onerror = languageChangeStat.onload; languageChangeStat.src = ‘https://pixel.wp.com/g.gif?v=wpcom-no-pv&x_language-switcher=manual-switch-‘ + locale + ‘&rm=’ + Math.random(); } document.body.addEventListener( ‘click’, ( event ) => { const { target } = event; if ( target.matches( ‘.lp-language-picker a[lang]’ ) ) { event.preventDefault(); const code = target.getAttribute( ‘lang’ ); const href = target.getAttribute( ‘href’ ); createLocaleCookie( code ); createStatsRequest( code, href ); } }); } /** * Loads and fires the Bing tracking pixel. */ const fireBing = () => { ( function( w, d, t, r, u ) { var f, n, i; w[ u ] = w[ u ] || [], f = function() { var o = { ti: “4074038” }; o.q = w[ u ], w[ u ] = new UET( o ), w[ u ].push( “pageLoad” ) }, n = d.createElement( t ), n.src = r, n.async = 1, n.onload = n.onreadystatechange = function() { var s = this.readyState; s && s !== “loaded” && s !== “complete” || ( f(), n.onload = n.onreadystatechange = null ) }, i = d.getElementsByTagName( t )[ 0 ], i.parentNode.insertBefore( n, i ) } )( window, document, “script”, “//bat.bing.com/bat.js”, “uetq” ); } /** * Adds a click event for Facebook pixel tracking on the /webinar sub pages. */ const trackFacebookWebinarClicks = () => { const facebookPixelURL = ‘https://www.facebook.com/tr?id=759053181468957&ev=SubscribedButtonClick&noscript=1’; const elementsToTrack = document.getElementsByClassName( ‘webinar-facebook-click-track’ ); const handleFacebookClickEvent = ( event ) => { const facebookImgPixel = document.createElement( ‘img’ ); facebookImgPixel.width = 1; facebookImgPixel.height = 1; facebookImgPixel.src = facebookPixelURL; document.body.appendChild( facebookImgPixel ); } Array.from( elementsToTrack ).forEach( ( element ) => element.addEventListener( ‘click’, handleFacebookClickEvent )); } // Apply the URL parameter linkers. applyLinkers(); // Add “essential” trackers to queue. cb.addTracker( ‘essential’, false, fireCurrencyHandlers ); // Add “analytics” trackers to queue. cb.addTracker( ‘analytics’, false, fireTracks ); cb.addTracker( ‘analytics’, false, fireAffiliateReferrals ); cb.addTracker( ‘analytics’, false, setupTracksGAClickTracking ); cb.addTracker( ‘analytics’, false, trackScrollPercentage ); cb.addTracker( ‘analytics’, false, setupLocaleChangeTracking ); cb.addTracker( ‘analytics’, true, fireGoogleAnalyticsFour ); cb.addTracker( ‘analytics’, true, () => fireParsely( ‘wordpress.com’ ) ); // Add “advertising” trackers to queue. cb.addTracker( ‘advertising’, true, loadGoogleAdsGtag ); cb.addTracker( ‘advertising’, true, fireFacebook ); cb.addTracker( ‘advertising’, true, trackFacebookWebinarClicks ); cb.addTracker( ‘advertising’, true, fireBing ); cb.addTracker( ‘advertising’, true, fireRedditAdvertisingPixel); // cb.addTracker( ‘advertising’, true, fireHotJar ); – Disabling for now. Enable when Hotjar is required to be used. // cb.addTracker( ‘advertising’, true, fireMicrosoftClarity ); – Disabling for now. cb.addTracker( ‘advertising’, true, fireImpactAffiliate ); // Maybe fire trackers now, via cookie banner, based on bucketed consent. cb.maybeFireTrackers(); }); }; // CCPA – Do Not Sell My Data. document.addEventListener( ‘a8c-analytics:loaded-is-ccpa’, ( event ) => { const { detail } = event; const isCCPAEligible = JSON.parse( detail ).isCCPA; if ( ! isCCPAEligible ) { document.querySelectorAll( ‘[data-is-ccpa-dnsd]’ ).forEach( ( element ) => { const parent = element.parentNode; const parentTagName = parent.tagName.toLowerCase(); // If the link in a part of a list, remove the entire parent item. // Otherwise, remove only the link element. ( parentTagName === ‘li’ ? parent : element ).remove(); } ); return; } document.querySelector( ‘[data-is-ccpa-dnsd-trigger]’ ).onclick = ( event ) => { event.preventDefault(); window.a8cAnalytics.dnsd.show(); }; } ); if ( window.defQueue && defQueue.isLOHP && defQueue.isLOHP === 2020 ) { defQueue.items.push( setupAnalytics ); } else { setupAnalytics(); } } )(); ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button