Skip to content
    Moz logo Menu open Menu close
    • Products
      • Moz Pro
      • Moz Pro Home
      • Moz Local
      • Moz Local Home
      • STAT
      • Mozscape API
    • Free SEO Tools
      • Competitive Research
      • Link Explorer
      • Keyword Explorer
      • Domain Analysis
      • 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 Tools

        The essential SEO toolset: keyword research, link building, site audits, page optimization, rank tracking, reporting, and more.

        Learn more
        Try Moz Pro free
        Illustration of Moz Pro
      • Moz Local

        Complete Local SEO Management

        Raise your local SEO visibility with easy directory distribution, review management, listing updates, and more.

        Learn more
        Check my presence
        Illustration of Moz Local
      • STAT

        Enterprise Rank Tracking

        SERP tracking and analytics for SEO experts, STAT helps you stay competitive and agile with fresh insights.

        Learn more
        Book a demo
        Illustration of STAT
      • Mozscape API

        The Power of Moz Data via API

        Power your SEO with the proven, most accurate link metrics in the industry, powered by our index of trillions of links.

        Learn more
        Get connected
        Illustration of Mozscape API
      • Compare SEO Products
    • Free SEO Tools
      • Competitive Research

        Competitive Intelligence to Fuel Your SEO Strategy

        Gain intel on your top SERP competitors, keyword gaps, and content opportunities.

        Find competitors
        Illustration of Competitive Research
      • Link Explorer

        Powerful Backlink Data for SEO

        Explore our index of over 40 trillion links to find backlinks, anchor text, Domain Authority, spam score, and more.

        Get link data
        Illustration of Link Explorer
      • Keyword Explorer

        The One Keyword Research Tool for SEO Success

        Discover the best traffic-driving keywords for your site from our index of over 500 million real keywords.

        Search keywords
        Illustration of Keyword Explorer
      • Domain Analysis

        Free Domain SEO Analysis Tool

        Get top competitive SEO metrics like Domain Authority, top pages, ranking keywords, and more.

        Analyze domain
        Illustration of Domain Analysis
      • MozBar

        Free, Instant SEO Metrics As You Surf

        Using Google Chrome, see top SEO metrics instantly for any website or search result as you browse the web.

        Try MozBar
        Illustration of MozBar
      • More Free SEO Tools
    • Learn SEO
      • Beginner's Guide to SEO

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

        Read the Beginner's Guide
      • How-To Guides

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

        See All SEO Guides
      • SEO Learning Center

        Broaden your knowledge with SEO resources for all skill levels.

        Visit the Learning Center
      • Moz Academy

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

        Explore the Catalog
      • On-Demand Webinars

        Learn modern SEO best practices from industry experts.

        View All Webinars
      • SEO Q&A

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

        Find SEO Answers
      The Impact of Local Business Reviews
      SEO Industry Report

      The Impact of Local Business Reviews

      Learn more
    • Blog
    • Why Moz
      • Small Business Solutions

        Uncover insights to make smarter marketing decisions in less time.

        Grow Your Business
      • The Moz Story

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

        Read Our Story
      • Agency Solutions

        Earn & keep valuable clients with unparalleled data & insights.

        Drive Client Success
      • Case Studies

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

        See What's Possible
      • Enterprise Solutions

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

        Scale Your SEO
      • New Releases

        Get the scoop on the latest and greatest from Moz.

        See What’s New
      Surface actionable competitive intel
      New Feature: Moz Pro

      Surface actionable competitive intel

      Learn More
    • Log in
      • Moz Pro
      • Moz Local
      • Moz Local Dashboard
      • Mozscape API
      • Mozscape 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

    Unsolved Capturing Source Dynamically for UTM Parameters

    Technical SEO
    technical seo google analytics utm parameters
    3
    3
    204
    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

          • davidboh

            Why is my inner pages ranking higher than main page?

            technical seo

            Hi everyone, for some reason lately i have discovered that Google is ranking my inner pages higher than the main subfolder page. www.domain.com/subfolder --> Target page to be ranked
            www.domain.com/subfolder/aboutus ---> page that is currently ranking Also in the SERP most of the time, it is showing both links in this manner. www.domain.com/subfolder/aboutus
            -----------www.domain.com/subfolder Thanks in advance.

            Technical SEO | | davidboh
            1
          • graceflack 0

            Abnormally High Direct Traffic Volume

            google analytics reporting

            We have abnormally high amounts of direct traffic to our site. It's comprising over half of all web traffic while organic is second with considerably less. From there the volume decreases amongst other channels. I've never seen such a huge proportion of traffic being attributed the Direct. Does anyone know how to test this or see if there is an error in Google Analytics reporting?

            Reporting & Analytics | | graceflack 0
            1
          • ben10001

            Footer External Links

            technical seo footer external links

            I manage a collection of 3 travel websites with DA's in 50's and 60's and have launched a new site which currently has a DA of 35. Currently there are no links between sites in the footer. Adding a footer link to new site from the existing stronger sites will be relevant to users on those sites. How would Google treat such footer links - we would be talking about a link from 5000+ pages from 3 sites?
            Would it help us on the new site? Damage the new site?
            Could it impact negatively on the currently strong websites? Thanks

            Technical SEO | | ben10001
            0
          • Tom3_15

            Dynamically Inserting Noindex With Javascript

            Hello, I have a broken plugin creating hundreds of WP-Content directory pages being indexed by Google. I can not access the source code of these pages to add a noindex to them. The page URL's all have the plugin name within them.  In order to resolve the issue, I wrote a solution with javascript to dynamically add in a noindex tag to any URL containing the plugin name. Would this noindex be respected by Google and is there a way to immediately check that it is respected? Currently, I can not delete the plugin due to issues with it's php. If you would like to view the code: https://codepen.io/trodrick/pen/Gwwaej?editors=0010 Thanks!

            Technical SEO | | Tom3_15
            0
          • Jane.com

            Do I submit a sitemap for a highly dynamic site or not? If so, what's the best way to go about doing it?

            I do SEO for online boutique marketplace. I've been here for about 4 weeks and no one's done there SEO (they've been around for about 5 years), so there's lots to do. A big concern is whether or not to submit a sitemap, and if I do submit one, what's the best way to go about doing one.

            Technical SEO | | Jane.com
            0
          • merch_zzounds

            Does Google add parameters to the URL parameters in webmaster tools/

            I am seeing new parameters added (and sometimes removed) from the URL Parameter tool.  Is there anything that would add parameters to the tool?  Or does it have to be someone internally? FYI - They always have no date in the configured column, no effect set, and crawl is set to Let Google decide.

            Technical SEO | | merch_zzounds
            0
          • jgodwin

            I am using All-in-One-seo. I change the title and meta description on the home page, but it is not showing up on the search. It is on the source code. When I change other pages, the both show up in the search, just not the home page. Any idea why?.

            Alll in one SEO

            Technical SEO | | jgodwin
            0
          • WendyWuTours

            Duplicate pages, overly dynamic URL’s and long URL’s in Magento

            Hi there, I’ve just completed the first crawl of my Magento site and SEOMOZ has picked up 1,000’s of duplicate pages, overly dynamic URL’s and long URL’s due to the sort function which appends URL’s with variables when sorting products (e.g. www.example.com?dir=asc&order=duration). I’m not particularly concerned that this will affect our rankings as Google has stated that they are familiar with the structure of popular CMS’s and Magento is pretty popular. However it completely dominates my crawl diagnostics so I can’t see if there are any real underlying issues. Does anyone know a way of preventing this? Cheers,
            Al.

            Technical SEO | | WendyWuTours
            1
          Moz logo
          • Contact
          • Community
          • Free Trial
          • Terms & Privacy
          • Jobs
          • Help
          • News & Press
          • Mozcon
          © 2021 - 2023 SEOMoz, Inc., a Ziff Davis company. All rights reserved. Moz is a registered trademark of SEOMoz, Inc.

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