Skip to content
    Moz logo Menu open Menu close
    • Products
      • Moz Pro
      • Moz Pro Home
      • Moz Local
      • Moz Local Home
      • STAT
      • Moz API
      • Moz API Home
      • Compare SEO Products
      • Moz Data
    • Free SEO Tools
      • Domain Analysis
      • Keyword Explorer
      • Link Explorer
      • Competitive Research
      • MozBar
      • More Free SEO Tools
    • Learn SEO
      • Beginner's Guide to SEO
      • SEO Learning Center
      • Moz Academy
      • SEO Q&A
      • Webinars, Whitepapers, & Guides
    • Blog
    • Why Moz
      • Agency Solutions
      • Enterprise Solutions
      • Small Business Solutions
      • Case Studies
      • The Moz Story
      • New Releases
    • Log in
    • Log out
    • Products
      • Moz Pro

        Your all-in-one suite of SEO essentials.

      • Moz Local

        Raise your local SEO visibility with complete local SEO management.

      • STAT

        SERP tracking and analytics for enterprise SEO experts.

      • Moz API

        Power your SEO with our index of over 44 trillion links.

      • Compare SEO Products

        See which Moz SEO solution best meets your business needs.

      • Moz Data

        Power your SEO strategy & AI models with custom data solutions.

      NEW Keyword Suggestions by Topic
      Moz Pro

      NEW Keyword Suggestions by Topic

      Learn more
    • Free SEO Tools
      • Domain Analysis

        Get top competitive SEO metrics like DA, top pages and more.

      • Keyword Explorer

        Find traffic-driving keywords with our 1.25 billion+ keyword index.

      • Link Explorer

        Explore over 40 trillion links for powerful backlink data.

      • Competitive Research

        Uncover valuable insights on your organic search competitors.

      • MozBar

        See top SEO metrics for free as you browse the web.

      • More Free SEO Tools

        Explore all the free SEO tools Moz has to offer.

      What is your Brand Authority?
      Moz

      What is your Brand Authority?

      Check yours now
    • Learn SEO
      • Beginner's Guide to SEO

        The #1 most popular introduction to SEO, trusted by millions.

      • SEO Learning Center

        Broaden your knowledge with SEO resources for all skill levels.

      • On-Demand Webinars

        Learn modern SEO best practices from industry experts.

      • How-To Guides

        Step-by-step guides to search success from the authority on SEO.

      • Moz Academy

        Upskill and get certified with on-demand courses & certifications.

      • SEO Q&A

        Insights & discussions from an SEO community of 500,000+.

      Unlock flexible pricing & new endpoints
      Moz API

      Unlock flexible pricing & new endpoints

      Find your plan
    • Blog
    • Why Moz
      • Small Business Solutions

        Uncover insights to make smarter marketing decisions in less time.

      • Agency Solutions

        Earn & keep valuable clients with unparalleled data & insights.

      • Enterprise Solutions

        Gain a competitive edge in the ever-changing world of search.

      • The Moz Story

        Moz was the first & remains the most trusted SEO company.

      • Case Studies

        Explore how Moz drives ROI with a proven track record of success.

      • New Releases

        Get the scoop on the latest and greatest from Moz.

      Surface actionable competitive intel
      New Feature

      Surface actionable competitive intel

      Learn More
    • Log in
      • Moz Pro
      • Moz Local
      • Moz Local Dashboard
      • Moz API
      • Moz API Dashboard
      • Moz Academy
    • Avatar
      • Moz Home
      • Notifications
      • Account & Billing
      • Manage Users
      • Community Profile
      • My Q&A
      • My Videos
      • Log Out

    The Moz Q&A Forum

    • Forum
    • Questions
    • Users
    • Ask the Community

    Welcome to the Q&A Forum

    Browse the forum for helpful insights and fresh discussions about all things SEO.

    1. Home
    2. SEO Tactics
    3. Technical SEO
    4. Capturing Source Dynamically for UTM Parameters

    Moz Q&A is closed.

    After more than 13 years, and tens of thousands of questions, Moz Q&A closed on 12th December 2024. Whilst we’re not completely removing the content - many posts will still be possible to view - we have locked both new posts and new replies. More details here.

    Unsolved Capturing Source Dynamically for UTM Parameters

    Technical SEO
    technical seo google analytics utm parameters
    3
    3
    1594
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as question
    Log in to reply
    This topic has been deleted. Only users with question management privileges can see it.
    • peteboyd
      peteboyd Subscriber last edited by

      Does anyone have a tutorial on how to dynamically capture the referring source to be populated in UTM parameters for Google Analytics?

      We want to syndicate content and be able to see all of the websites that provided referral traffic for this specific objective. We want to set a specific utm_medium and utm_campaign but have the utm_source be dynamic and capture the referring website.

      If we set a permanent utm_source, it would appear the same for all incoming traffic.

      Thanks in advance!

      Fabian001 1 Reply Last reply Reply Quote 0
      • Shaman-Das-khatri
        Shaman-Das-khatri last edited by

        @peteboyd said in Capturing Source Dynamically for UTM Parameters:

        Thanks in advance!

        UTM (Urchin Tracking Module) parameters are tags that you can add to the end of a URL in order to track the effectiveness of your marketing campaigns. These parameters are used by Google Analytics to help you understand how users are interacting with your website and where they are coming from.

        There are five different UTM parameters that you can use:

        utm_source: This parameter specifies the source of the traffic, such as "google" or "Facebook".

        utm_medium: This parameter specifies the medium of the traffic, such as "cpc" (cost-per-click) or "social".

        utm_campaign: This parameter specifies the name of the campaign, such as "spring_sale" or "promotion".

        utm_term: This parameter specifies the term or keywords used in the campaign, such as "shoes" or "dress".

        utm_content: This parameter specifies the content of the ad, such as the headline or the call-to-action.

        To capture the source dynamically for UTM parameters, you can use JavaScript to get the value of the document. referrer property. This property returns the URL of the page that is linked to the current page. You can then use this value to set the utm_source parameter dynamically.

        For example, you might use the following code to set the utm_source parameter based on the referring URL:

        Copy code
        var utmSource = '';

        if (document.referrer.indexOf('google') !== -1) {
        utmSource = 'google';
        } else if (document.referrer.indexOf('facebook') !== -1) {
        utmSource = 'facebook';
        }

        // Add the utm_source parameter to the URL
        var url = 'http://www.example.com?utm_source=' + utmSource;
        This code will set the utm_source parameter to "google" if the user came to the page from a Google search or to "Facebook" if the user came to the page from Facebook. If the user came to the page from another source, the utm_source parameter will be left empty.

        You can then use this modified URL in your marketing campaigns to track the effectiveness of your campaigns and understand where your traffic is coming from.

        1 Reply Last reply Reply Quote 0
        • Fabian001
          Fabian001 @peteboyd last edited by

          @peteboyd you can refer to this tutorial: https://www.growwithom.com/2020/06/16/track-dynamic-traffic-google-tag-manager/

          Should meet your requirements perfectly - using GTM to replace a static value with the url in your UTM Source.

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post

          Got a burning SEO question?

          Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.


          Start my free trial


          Browse Questions

          Explore more categories

          • Moz Tools

            Chat with the community about the Moz tools.

          • SEO Tactics

            Discuss the SEO process with fellow marketers

          • Community

            Discuss industry events, jobs, and news!

          • Digital Marketing

            Chat about tactics outside of SEO

          • Research & Trends

            Dive into research and trends in the search industry.

          • Support

            Connect on product support and feature requests.

          • See all categories

          Related Questions

          • inhouseninja

            Huge Drop in Direct Traffic in G4

            google analytics direct traffic

            Our direct traffic dropped 50% in October. Is anyone else seeing a drop in direct traffic in October in G4? It hasn't shifted to another source or unassigned it's just gone. Has anyone else experienced this and what might be the reasons?

            Intermediate & Advanced SEO | | inhouseninja
            1
          • williamhuynh

            Good to use disallow or noindex for these?

            technical seo noindex disallow

            Hello everyone, I am reaching out to seek your expert advice on a few technical SEO aspects related to my website. I highly value your expertise in this field and would greatly appreciate your insights.
            Below are the specific areas I would like to discuss: a. Double and Triple filter pages: I have identified certain URLs on my website that have a canonical tag pointing to the main /quick-ship page. These URLs are as follows: https://www.interiorsecrets.com.au/collections/lounge-chairs/quick-ship+black
            https://www.interiorsecrets.com.au/collections/lounge-chairs/quick-ship+black+fabric Considering the need to optimize my crawl budget, I would like to seek your advice on whether it would be advisable to disallow or noindex these pages. My understanding is that by disallowing or noindexing these URLs, search engines can avoid wasting resources on crawling and indexing duplicate or filtered content. I would greatly appreciate your guidance on this matter. b. Page URLs with parameters: I have noticed that some of my page URLs include parameters such as ?variant and ?limit. Although these URLs already have canonical tags in place, I would like to understand whether it is still recommended to disallow or noindex them to further conserve crawl budget. My understanding is that by doing so, search engines can prevent the unnecessary expenditure of resources on indexing redundant variations of the same content. I would be grateful for your expert opinion on this matter. Additionally, I would be delighted if you could provide any suggestions regarding internal linking strategies tailored to my website's structure and content. Any insights or recommendations you can offer would be highly valuable to me. Thank you in advance for your time and expertise in addressing these concerns. I genuinely appreciate your assistance. If you require any further information or clarification, please let me know. I look forward to hearing from you. Cheers!

            Technical SEO | | williamhuynh
            0
          • Ravi_Rana

            Why Product pages are throwing Missing field "image" and Missing field "price" in Wordpress Woocommerce

            technical seo structured data woocommerce wordpress seo

            I have a wordpress wocommerce website where I have uploaded 100s of products but it's giving me error in GSC under merchant listing tab. When I tested it show missing field image and missing field price. I have done everything according to https://developers.google.com/search/docs/appearance/structured-data/product#merchant-listing-experiences and applied fixed i.e. images are 800x800 and price range is also there. What else can be done here?!merchant listing.jpg

            Technical SEO | | Ravi_Rana
            0
          • Dingos

            URL structure for same product in multiple categories?

            url inspection breadcrumbs technical seo seo tactics

            Hello everyone ! I am building an ecom store using wordpress. I have assigned multiple categories to the same product. What should be the URL structure when users are navigating with different product categories? Categories Assigned: tshirt, blue, striped
            Product Name: blue-striped-tshirt Option 01: Matching site navigation breadcrumb to product url URL - ecomstore.com/tshirt/blue-striped-tshirt
            Breadcrumb - home/tshirt/blue-striped-tshirt URL - ecomstore.com/blue/blue-striped-tshirt (canonical to 1 product page)
            Breadcrumb - home/color/blue/blue-striped-tshirt URL - ecomstore.com/striped/blue-striped-tshirt (canonical to 1 product page)
            Breadcrumb - home/type/striped/blue-striped-tshirt Option 02: Same product urls and different breadcrumbs based on user site navigation URL - ecomstore.com/tshirt/blue-striped-tshirt
            Breadcrumb - home/tshirt/blue-striped-tshirt URL - ecomstore.com/tshirt/blue-striped-tshirt (url same as 1 product page)
            Breadcrumb - home/color/blue/blue-striped-tshirt URL - ecomstore.com/tshirt/blue-striped-tshirt (url same as 1 product page)
            Breadcrumb - home/type/striped/blue-striped-tshirt I have decided to got with Option 01 so that the product in each category can be ranked according to each category keyword. Which option is the best according to your experience or is there any other best practice?

            Technical SEO | | Dingos
            0
          • bradsimonis

            What's Causing My Extremely Low Bounce Rate

            google analytics google tag manager bounce rate

            My client's site that is reporting an under 10% bounce rate for all sources. Direct is the highest at 8%. I'm no expert in GA but wondering if there is a problem with the analytics/tag manager code on the site. I'm especially concerned about the GTM body script being in an iframe which I read could be trouble. <!-- Google Tag Manager (noscript) -->
            <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-MWGMNW6"
            height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
            <!-- End Google Tag Manager (noscript) --> You can see all the source code here:
            view-source:https://nfinit.com/

            Reporting & Analytics | | bradsimonis
            0
          • echo1

            Mobile URL parameter (Redirection to desktop)

            Hello, We have a parallel mobile website and recently we implemented a link pointing to the desktop website. This redirect is happening via a javascript code and results in a url followed by this paramenter: ?m=off Example:
            http://www.m.website.com                                 redirects to:
            http://www.website.com/?m=off Questions: Will the "http://www.website.com/?m=off" be considered duplicate content with "http://www.website.com" since they both return the same content? Is there any possibility that Google will take into consideration the url ending in "/?m=off"? How should we treat this new url? The webmaster tools URL parameter configuration at the moment isn't experiencing problems but should we submit the parameter anyway in order not to be indexed or should we wait first and see the error response? In case we should submit this for removal... what's the best way to do it? Like this? Parameter: ?m=off Does this parameter change page content seen by the user? - doesn't affect page content Any help is much appreciated.
            Thank you!

            Technical SEO | | echo1
            0
          • jfmonfette

            Dynamically changing a title with javascript

            Hi, I asked our IT team to be able to write custom page titles in our CMS and they came up with a solution that writes the title dynamically with javascript. When I look on the page, I see the title in the browser, but when I look in the source code, I see the original page title. I am thinking that Google won't see the new javascript title, so it will not be indexed and have no impact on SEO. Am I right ?

            Technical SEO | | jfmonfette
            0
          • SEOPractices

            Best Dynamic Sitemap Generator

            Hello Mozers, Could you please share the best Dynamic Sitemap Generator you are using.  I have found this place: http://www.seotools.kreationstudio.com/xml-sitemap-generator/free_dynamic_xml_sitemap_generator.php Thanks in advanced for your help.

            Technical SEO | | SEOPractices
            0

          Get started with Moz Pro!

          Unlock the power of advanced SEO tools and data-driven insights.

          Start my free trial
          Products
          • Moz Pro
          • Moz Local
          • Moz API
          • Moz Data
          • STAT
          • Product Updates
          Moz Solutions
          • SMB Solutions
          • Agency Solutions
          • Enterprise Solutions
          Free SEO Tools
          • Domain Authority Checker
          • Link Explorer
          • Keyword Explorer
          • Competitive Research
          • Brand Authority Checker
          • MozBar Extension
          • MozCast
          Resources
          • Blog
          • SEO Learning Center
          • Help Hub
          • Beginner's Guide to SEO
          • How-to Guides
          • Moz Academy
          • API Docs
          About Moz
          • About
          • Team
          • Careers
          • Contact
          Why Moz
          • Case Studies
          • Testimonials
          Get Involved
          • Become an Affiliate
          • MozCon
          • Webinars
          • Practical Marketer Series
          • MozPod
          Connect with us

          Contact the Help team

          Join our newsletter
          Moz logo
          © 2021 - 2025 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.
          • Accessibility
          • Terms of Use
          • Privacy

          Looks like your connection to Moz was lost, please wait while we try to reconnect.