Hi Team,
Please assist with this query:
We have to track engagements in marketo from the website landing pages via an ad campaign.
We have a google ad clicking on the ad (this is UTM tracking link) takes us on the website LP, website page has assets link, clicking on each of the asset link, will take us to other website landing page where we have gated form fill, filling out the form the asset is download.
Now the issue here is though I qualify in the ad campaign (I have set up the logic), but the lead source gets attributed to website and not ad channel (here channel is google) ; I also get qualified in website program for filling out the form but I should be qualified only in ad campaign.
I have set up many tracking program to capture engagements from Marketo landing pages where we can add UTMs to the assets and it attributed to the source correctly, but since it's the website landing pages, I see this issue.
Please suggest what's the best way to set this up.
Thanks,
Deepthi.
Solved! Go to Solution.
Careful, that code has a bug because it’ll overwrite the entire existing query string of links on the page.
You want to merge the query strings.
document.addEventListener("DOMContentLoaded", function(e){
const copyableParamNames = ["utm_source", "utm_medium", "utm_campaign"];
const currentURL = new URL(document.location.href),
currentSearch = currentURL.searchParams;
const copyableEntries = Array.from(currentSearch.entries())
.filter( ([name,value]) => copyableParamNames.includes(name) );
Array.from(document.links)
.filter( (link) => link.href )
.forEach( (link) => {
const linkURL = new URL(link.href, currentURL.href);
copyableEntries.forEach( ([name,value]) => linkURL.searchParams.set(name,value) );
link.href = linkURL.href;
});
});
The reason why the tracking is attributed to the default source, i.e., direct/website is because you don't have UTMs on each of the gated content pages where the person is actually filling out the form. It appears to me that if you carry forward your tracking UTMs from the first LP that has links to all the gated content to the subsequent LPs (i.e., each gated asset website link), your issue should get resolved. Since you're already doing UTM tracking, I'm assuming you would have already added hidden fields on the form and the autofill logic on those to capture the UTM parameters from the URL upon a form fill.
Hi Darshil,
It appears to me that if you carry forward your tracking UTMs from the first LP that has links to all the gated content to the subsequent LPs (i.e., each gated asset website link), your issue should get resolved.
- Exactly, this is the problem, how to get this resolved. The UTM is added to the main landing page, when I click on the asset (with no UTM's) takes me to other landing page (so I go to this landing page with no UTM) and fills out a form; the thing is I have set the the ad campaign to capture engagements which works fine, but the lead source gets attributed to website because I first qualify in the website program which attributes lead source to website and then I qualify in the ad campaign.
So how to set up the program in such a way:
I dont get qualified in website program
Lead source value should be ad channel
Thanks,
Deepthi.
As I said in my previous comment, one way is to carry forward the relevant UTM parameters for capturing the source, medium, campaign, etc. from the initial page to the next page. Hidden fields on the form can just capture those UTM parameter values and you won't need a campaign as well. But of course, if you're doing other steps like Change Program Status, Sync to SFDC, etc., you'd still need a smart campaign to do all of those, but you'd not need a dedicated flow step to write the values that are already captured by the form's autofill hidden fields functionality.
Below is a sample JS that grabs the UTM parameters (utm_source, utm_medium, and utm_campaign) from the source page, and appends it to the subsequent page URLs when a person navigates from it. Let us know if you have questions. Note that the script assumes that the links on the page don't have any UTMs added to them in the end by default.
// Function to retrieve UTM parameters from the current page's URL
function getUTMParameters() {
var urlParams = new URLSearchParams(window.location.search);
var utmParameters = {};
// Add specific UTM parameters to the object if they exist in the URL
if (urlParams.has('utm_source')) {
utmParameters.utm_source = urlParams.get('utm_source');
}
if (urlParams.has('utm_medium')) {
utmParameters.utm_medium = urlParams.get('utm_medium');
}
if (urlParams.has('utm_campaign')) {
utmParameters.utm_campaign = urlParams.get('utm_campaign');
}
// Add more UTM parameters as needed
return utmParameters;
}
// Function to append UTM parameters to clicked links
function appendUTMToLinks() {
var links = document.getElementsByTagName('a');
var utmParameters = getUTMParameters();
for (var i = 0; i < links.length; i++) {
var link = links[i];
var href = link.getAttribute('href');
// Check if the link has an href attribute
if (href) {
// Append UTM parameters to the link's URL
var url = new URL(href, window.location.href);
url.search = new URLSearchParams(utmParameters).toString();
// Set the updated URL as the new href
link.setAttribute('href', url.toString());
}
}
}
// Call the function to append UTM parameters when the page loads
appendUTMToLinks();
Than you Darshil.
Got your point, all good now.
Thanks,
Deepthi.
Careful, that code has a bug because it’ll overwrite the entire existing query string of links on the page.
You want to merge the query strings.
document.addEventListener("DOMContentLoaded", function(e){
const copyableParamNames = ["utm_source", "utm_medium", "utm_campaign"];
const currentURL = new URL(document.location.href),
currentSearch = currentURL.searchParams;
const copyableEntries = Array.from(currentSearch.entries())
.filter( ([name,value]) => copyableParamNames.includes(name) );
Array.from(document.links)
.filter( (link) => link.href )
.forEach( (link) => {
const linkURL = new URL(link.href, currentURL.href);
copyableEntries.forEach( ([name,value]) => linkURL.searchParams.set(name,value) );
link.href = linkURL.href;
});
});
Ahaa! That makes sense, Sandy! Wouldn't wanna let go of any parameters already added to the links. Thank you! Appreciate it as always.