I've been trying to extract individual key value pairs from a query string....we've been seeing UTM parameters in our Full Page URLs reports in AA. Right now we're using the cmpid value for campaigns, so I can't replace this value with utm
Example:
Query String (we see the full string):utm_source=google&utm_medium=organic&utm_campaign=local&utm_content=downtown
I am trying to extract each utm parameter separately (in the below example, the DE is added to a Page Load rule and in AA we'd see "Custom Conversion > prop74 > UTM Source > google)
UTM Source Data Element
var params = {};
if (location.search) {
var parts = location.search.substring(1).split('&');
for (var i = 0; i < parts.length; i++) {
var nv = parts[i].split('=');
if (!nv[0]) continue;
params[nv[0]] = nv[1] || true;
}
var utm_source = params.utm_source;
This is set to a page load rule - mapped back to either eVar74 or prop74
I'm seeing the output when I test this code in the console - but it doesn't work in DTM...
Any help is REALLY appreciated!
Solved! Go to Solution.
Views
Replies
Total Likes
Hi paulinamb
To get a single query string parameter in a dataelement, simple change the dataelement to fetch the value directly (no javascript needed). see here: Get value of URL parameter for data elements
need an improvement?
Some time ago I wrote an answer to get all utm parameters in one dataelement: Using UTM parameters in Adobe Analytics
Now you can save all your concatenated parameters in one evar and use classification rules to split it apart for reporting. this might save you some evars if you want to to your code for more than one variable...
Hi paulinamb
To get a single query string parameter in a dataelement, simple change the dataelement to fetch the value directly (no javascript needed). see here: Get value of URL parameter for data elements
need an improvement?
Some time ago I wrote an answer to get all utm parameters in one dataelement: Using UTM parameters in Adobe Analytics
Now you can save all your concatenated parameters in one evar and use classification rules to split it apart for reporting. this might save you some evars if you want to to your code for more than one variable...
Hi!
Thanks for the response! Unfortunately this solution won't work for us. We don't have these elements set up in the data layer which is why I need this as a custom script.
Also can't assign these are our main campaign tracking id (i.e. we use cmpid for now).
Thanks for the response - if you have any insight it's still really apprecaited
Views
Replies
Total Likes
What do you mean by "it does not work"? why not?
the solution in the first link maps a single dataelement to any desired query string parameter. read here: Get value of URL parameter for data elements I think this is exactly the same as you try with your custom code ... so just change your dataelement ...
Views
Replies
Total Likes
HI again
Thanks for taking the time to respond. I discovered that it both (script and the solution you provided) works only if the below are selected - SO odd since I'd tried this previously but now I'm seeing it work...
Thanks again for the prompt responses. I hope you have a nice rest of the weekend