Some plugins and themes rely on the session information for their functionality. When switching languages, the session information is lost, visitors might not see their products in the cart anymore. WPML provides a mechanism to synchronize this session data between domains and languages.
On the WPML → Languages page, under the Language URL Format section, you can find the Pass session arguments between domains through the language switcher option. It synchronizes this session data among domains and languages.
Why WPML needs to synchronize session data between languages in domains
Browsers keep information in what’s called cookies or sessions. When you go to a site that’s supposed to ‘know you’, the site will display personalized content. You can see this on many e-commerce and membership sites. The browser keeps some information about you in its storage and sends it to the server. The server uses this information to continue your previous browsing session.
Browsers must maintain a strict isolation for this session information between different sites. Some of the session information stored in your browser includes login details or payment information. Obviously, you don’t want your payment details on Amazon to be shared with other sites which are not amazon.com.
WPML allows sites to deliver languages from different domains. Since browsers don’t know that it’s actually the same site, the browsers are correct by isolating the session information between languages. So, WPML includes its own mechanism that passes session information between languages. Don’t worry. This mechanism only passes session information between domains that WPML serves. This way, your visitors can switch languages and enjoy persistent browser storage.
How WPML synchronizes session data between languages in different domains
When you configure WPML to use languages in domains, WPML knows that it needs to synchronize session information between languages. We’ve created a filter in WPML called wpml_cross_domain_language_data. This filter allows plugins and themes to pass necessary information between domains.
Our WooCommerce Multilingual uses this filter to pass the cart cookie.
So, when you use languages in domains and there are cookies that need to be synchronized when switching languages, you will see arguments appended to the language switcher’r URLs.
It will look like:
sample.es?xdomain_data=LONG_STRING
This ‘magical’ xdomain_data argument includes the information to set the cookie after switching languages.
Does the xdomain_data argument cause SEO problems?
Not at all. WPML adds the xdomain_data argument using Javascript in the browser (remember that we’re encoding cookies from the browser?).
The only one to see this argument is the user who has the cookies. That information is not available in the page that’s rendered from WordPress. It’s added later, on the user side. The information will arrive at the web server only when switching languages (and the information is actually needed).
You will never see URLs with xdomain_data in your sitemap or in indexed pages. Google never sees these arguments in the page source. You WILL see the xdomain_data in Google Analytics (sometimes) because these are actual links that visitors click on. This is fine and doesn’t have any negative consequences for Google or SEO.
Will this mechanism work with my custom language switcher?
If you create your custom language switcher using WPML’s language switcher API, it will work. Since the information is added using JS, as long as our JS recognizes the language switcher URLs, it will add the necessary argument to them.