In e-commerce websites, one common issue is the loss of tracking for URL query parameters associated with advertising campaigns and/or affiliate links, especially when the page performs self-referral (self-refreshing), which often occurs in SPA (Single Page Applications), either due to technical issues or otherwise. Tracking tools can provide various solutions for such scenarios.
GTM - Conversion Linker (Conversion Linker) article discusses the Conversion Linker, one of these solutions. In this article, I will discuss a simple alternative solution that assists in transferring the URL parameters, excluding the Conversion Linker.
Visitors arriving at your website or app may have interacted with various sources before reaching the content or products you offer. These sources may include advertisements or affiliate platforms. Due to various reasons—such as GDPR implementations, page self-refreshing, and URL data being deleted or obscured—data within URLs may be lost. In such cases, visitor traffic may be attributed to another source or directly, without the original URL data. In these scenarios, Google Tag Manager (GTM) provides a Conversion Linker (Conversion Tracker) to pass parameters (such as the _gl parameter in Google’s case) across domain and page boundaries, while the Global Site Tag (GTAG) offers a linker parameter to achieve the same. Regardless of which method is chosen, the primary objective is to share first-party measurement cookies between the source and destination domains1. The article titled GTM - Conversion Linker covers various details in this context. However, this solution may not be sufficient on its own, as it only ensures that relevant information is passed through query or fragment parameters2. Nevertheless, many websites and e-commerce stores use various redirection features for language, currency, and location settings. These solutions, however, rarely leverage links or forms.
In the following example scenario, when you arrive at a website, a popup with language and location selection options appears. Let’s assume the displayed URL is in the format https://ceaksin.com/?utm_source=google&utm_campaign=discount&ref=XXXX&gclid=YYYY.
IMPORTANT RULES:
- Maintain the original formatting (markdown, HTML tags, links, etc.)
- Keep technical terms and proper nouns as appropriate
- Preserve code blocks and technical syntax exactly
- Maintain the same tone and style
- Only output the translated text, no explanations or comments
When a hidden element with a redirect_to name attribute or a button with a data-url attribute is used for the relevant dropdown selection, the Conversion Linker will not be able to provide functionality for the redirection process.
<button type="button" class="button_class" data-url="https://ceaksan.com/location">Click Me!</button>
In such cases, several methods can be employed to ensure that relevant one or more parameters are not lost during the redirection process, including storing the relevant information in localStorage or a cookie, assigning the relevant information to a separate form element, submitting the form with the form data, retrieving the relevant information via JavaScript, and appending it to the element. In this article, we will provide an example of retrieving the relevant information via JavaScript and appending it to the specified element.
Example of Parameter Addition Process
Let’s assume the problematic situation occurs when a button is present in different sections of the site or within a popup that displays to the visitor, and we combine this with the previous example link. The goal is to append the existing ?utm_source=google&utm_campaign=discount&ref=XXXX&gclid=YYYY information to the https://ceaksan.com/location URL contained in the button’s data-url attribute, and redirect to /location?utm_source=google&utm_campaign=discount&ref=XXXX&gclid=YYYY.
For such a scenario, the following code snippet can be used as a solution.
Together with this action, when a user transitions to a different domain or subdomain via a form, the relevant parameters will also be carried over. The corresponding code snippet collects the parameters from the URL and appends them to the data-url attribute specified in data-url. Of course, the relevant parameters can be duplicated, and a form element with a href or redirect_to name can be defined instead of data-url.
The relevant code snippet can be directly added to the website and appended to the relevant page. However, I recommend adding it via the Custom HTML tag in Google Tag Manager so that it functions on the relevant page(s).
The above example is based on a simple use case and includes a corresponding solution. Naturally, methods to be followed in the context of consent solutions are somewhat more complex and include certain rules that must be observed.
*[SPA]: Single Page Application