How can I pass UTM parameters from a Webflow marketing website to a mobile web app without creating new forms with hidden fields?

Published on
September 22, 2023

To pass UTM parameters from a Webflow marketing website to a mobile web app without creating new forms with hidden fields, you can use JavaScript code. This approach allows you to extract the UTM parameters from the URL and then use them as needed in your mobile web app.

Here's a step-by-step guide on how to achieve this:

  1. Set up the UTM parameters in Webflow: Make sure that your Webflow marketing website is correctly configured to append UTM parameters to the URLs of your links. You can do this by navigating to the Project Settings in Webflow, selecting the Integrations tab, and enabling the "Append UTM parameters" option.

  2. Access the UTM parameters using JavaScript: In your mobile web app, you'll need to retrieve the UTM parameters from the URL. You can do this using JavaScript's URLSearchParams API. This API allows you to retrieve the query parameters from the URL.

    ```javascript
    const queryParams = new URLSearchParams(window.location.search);
    const utmSource = queryParams.get('utm_source');
    const utmMedium = queryParams.get('utm_medium');
    const utmCampaign = queryParams.get('utm_campaign');
    // Retrieve other relevant UTM parameters, if needed
    ```

  3. Pass the UTM parameters to your mobile web app: Once you've extracted the UTM parameters, you can pass them to your mobile web app by storing them in a JavaScript object or by using an appropriate data interchange format like JSON.

    ```javascript
    const utmParams = {
    utmSource,
    utmMedium,
    utmCampaign,
    // Add other relevant UTM parameters, if needed
    };

    // Pass the UTM parameters to your mobile web app using an appropriate method (e.g., local storage, session storage, postMessage, etc.)
    // Example using local storage:
    localStorage.setItem('utmParams', JSON.stringify(utmParams));
    ```

  4. Retrieve and use the UTM parameters in your mobile web app: Now, in your mobile web app, you can retrieve the UTM parameters and utilize them as required. The method for retrieving the parameters will depend on how you passed them in the previous step.

    ```javascript
    // Example using local storage:
    const utmParams = JSON.parse(localStorage.getItem('utmParams'));

    // Use the UTM parameters in your mobile web app
    console.log(utmParams.utmSource);
    console.log(utmParams.utmMedium);
    console.log(utmParams.utmCampaign);
    ```

By following these steps, you can pass UTM parameters from a Webflow marketing website to a mobile web app without relying on hidden form fields. This approach allows you to extract the UTM parameters directly from the URL using JavaScript, making them available for use in your mobile web app.

Additional Questions:

  1. How do I retrieve query parameters from a URL in JavaScript?
  2. What are UTM parameters and how are they used in marketing?
  3. Can I pass UTM parameters from Webflow to other third-party tools?