Unsolved Capturing Source Dynamically for UTM Parameters
-
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!
-
@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.
-
@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.
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
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.
Related Questions
-
Old Blogs
We have several blogs on our site for a range of products we no longer stock. Would you set up a redirect for these - and how long would you keep it in place?
Technical SEO | | Caroline_Ardmoor0 -
Unsolved MOZ API to Google Data Studio
Dopes MOZ have anything like this? https://www.semrush.com/features/google-data-studio-connector/
Product Support | | WebMarkets0 -
301 Redirects from example.com to store.example.com and then removing store.example.com subdomain
Hi I'm trying to wrap my head around the best approach for migrating our website. We're migrating from our example.com (joomla) site to our existing store.example.com (shopify) site... with the plan to finish the redirects/migration then remove the subdomain from shopify and use example.com moving forward. I've never done this and asking here to see if any harm will come from re-directing example.com URLs to store.example.com URL's then changing the store.example.com URL's to example.com. Right now my plan would run like this: redirect example.com URL's to store.example.com remove subdomain on store.example.com use example.com moving forward. wonder what happens next? Is there going to be any issues here, possible harm to the URL's?
Technical SEO | | Minarets0 -
blog url structure change affect on pagerank
We are looking to change our blog structure which will help us with the organization of the topics but the url structure will change if we do this. Right now all of the blogs are under a general news blog, which we will be breaking out articles into several blog category topics Current:
Technical SEO | | theblueprints
example of current structure
current site: https://domain/blogs/news/blog article name Proposed Change:
current site: https://domain/blogs/keyword-name-of-blog-category/blog article name We have ranked #1 for several keywords that we would like to preserve the ranking if we make this switch with 301 redirects. Looking for suggestion on the percentage of chance our ranking will be negatively affected and by how much? Also what everyones recommendation is if we should make this switch or not touch the urls. Your help is appreciated, thanks in advance.0 -
Since implementing GDPR, has anyone seen website traffic plummet?
On December 1 and 2, I implemented a cookie banner on 5 of my Wix sites (https://www.sanitationsolutionsinc.com is one example) in order to be in compliance with GDPR, CCPA, and LGPD. Since then my traffic according to Wix Analytics and Google Analytics has plummeted. Anyone else have the same issue? How did you fix it?
Reporting & Analytics | | Jason_Taylor0 -
XML Sitemap and unwanted URL parameters
We currently don't have an XML sitemap for our site. I generated one using Screaming Frog and it looks ok, but it also contains my tracking url parameters (ref=), which I don't want Google to use, as specified in GWT. Cleaning it will require time and effort which I currently don't have. I also think that having one could help us on Bing. So my question is: Is it better to submit a "so-so" sitemap than having none at all, or the risks are just too high? Could you explain what could go wrong? Thanks !
Technical SEO | | jfmonfette0 -
Overly-Dynamic Urls how to fix in SEOMOZ?
Hello. I have about 300 warnings of overly-dynamic urls. In urls like this: http://www.theprinterdepo.com/clearance?dir=asc&order=price&p=10 As you can see all parameters are needed, and my ecommerce solution generates them automatically. How can I get rid of these warnings? I suppose that by using robots.txt, but I have no idea about it. In my google webmaster tools I have already configured that these parameteres the crawler should not index them. Check the image here: http://imageshack.us/photo/my-images/64/37092444.png/
Technical SEO | | levalencia10