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

          • mohammadrehanseo

            How to Boost Your WordPress Website Speed to 95+ (Without Premium Plugins)

            speed wordpress website speed technical seo

            I'm reaching out for some advice on improving my WordPress website's speed. I'm currently using a free theme for this fusion magazine and aiming for a score of 95+ on Google PageSpeed Insights. I'm aware that premium plugins can significantly enhance performance, but I'm hoping to achieve similar results using primarily free solutions and manual optimizations.

            Technical SEO | | mohammadrehanseo
            0
          • davidevans_seo

            Unsolved Landing pages report has no data even if I have ranking keywords and traffic

            landing pages reporting rankings google analytics

            Is there any reason my landing page report does not include data for pages? I'm sure there is organic traffic on them, and I have tracked the correct keywords. Any similar insight will be helpful.

            Moz Tools | | davidevans_seo
            0
          • fbcosta

            How to index e-commerce marketplace product pages

            technical seo ecommerce indexation crawl product page

            Hello! We are an online marketplace that submitted our sitemap through Google Search Console 2 weeks ago. Although the sitemap has been submitted successfully, out of ~10000 links (we have ~10000 product pages), we only have 25 that have been indexed. I've attached images of the reasons given for not indexing the platform. gsc-dashboard-1 gsc-dashboard-2 How would we go about fixing this?

            Technical SEO | | fbcosta
            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
          • HashtagHustler

            Cant find source of redirect

            Hey guys, I have a bizarre situation on my hands. I have a URL that is being wonky. The url is redirecting to another url and the 301 redirect is not in my htaccess. There is a 301 redirect in my htaccess but is being overwritten by something else, i.e. whatever is happening in above. So basically URL A should be redirecting to URL B but instead its going to URL C. I know we were not hacked, it's not redirecting to a strange bizarre domain. I have also disabled all of our plugins that redirect (to my knowledge) Any thoughts would be great!

            Technical SEO | | HashtagHustler
            0
          • ey_sja

            How Does Dynamic Content for a Specific URL Impact SEO?

            Example URL:  http://www.sja.ca/English/Community-Services/Pages/Therapy Dog Services/default.aspx The above page is generated dynamically depending on what province the visitor visits from.  For example, a visitor from BC would see something quite different than a visitor from Nova Scotia; the intent is that the information shown should be relevant to the user of that province. How does this effect SEO?  How (or from what location) does Googlebot decide to crawl the page? I have considered a subdirectory for each province, though that comes with its challenges as well.  One such challenge is duplicate content when different provinces may have the same information for some pages.  Any suggestions for this?

            Technical SEO | | ey_sja
            0
          • SmartWebPros

            How to search HTML source for an entire website

            Is there a way for me to do a "view source" for an entire website without having to right-click every page and select "view source" for each of them?

            Technical SEO | | SmartWebPros
            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.