embedded data in website app intercept | XM Community
Skip to main content

Hi folks, I want to extract the number highlighted in yellow from below url as an embedded data in data and analysis section of Qualtrics for a website/app insights project. I have pasted the below code in the intercept under “add Javascript” option. However, still the code for some reason does not seem to work. I have also set the embedded data in Qualtrics for the field “extractedNumber”

 

https://www.merkle.com/en/careers/jobs.html/rs/743999952894453.html

 

// Get the current URL
const currentURL = window.location.href;

// Split the URL using '/' as a separator
const urlParts = currentURL.split('/');

// Find the part of the URL that contains the number
let extractedNumber = null;
urlParts.forEach(part => {
    if (!isNaN(part) && part.length > 12) {
        // Assuming the number has a length greater than 12
        extractedNumber = part;
    }
});

// Set the extracted number as Qualtrics embedded data
Qualtrics.SurveyEngine.setEmbeddedData('extractedNumber', extractedNumber);
 

Can someone help?

 

 

Hi,

If you split with /, your part will be “743999952894453.html”, not “743999952894453”.

Assuming you only want to record numbers with more than 12 digits and that you are certain there can’t be more than one of them in your URL, I would go with something like this :

const currentURL = window.location.href;
let extractedNumber = currentURL.match(/(\d{13,})/);
Qualtrics.SurveyEngine.setEmbeddedData('currentURL', currentURL);
Qualtrics.SurveyEngine.setEmbeddedData('extractedNumber', extractedNumbera1]);

 

 


Hi Vincent, I tried putting this code in JavaScript section of the question as well as the intercept, but it didn’t work. Can you please let me know where do I put this code and how do I pull the number as embedded data in the data and analysis section?


I think in your use case, you could simply use the URL Regex ED option in the intercept itself.

Set this in your intercept and add urlRegex in your survey flow

 

 


Thanks a ton, Vincent. It worked perfectly well. Thanks a lot once again. Happy Learning :)


Hi Vincent, just out of curiosity, can you also let me know if we were to accomplish this same thing using JavaScript, then where do we put the below code in the intercept? It would be super helpful if you can share a screenshot like you shared previously for urlRegex.

 

const currentURL = window.location.href; let extractedNumber = currentURL.match(/(\d{13,})/); Qualtrics.SurveyEngine.setEmbeddedData('currentURL', currentURL); Qualtrics.SurveyEngine.setEmbeddedData('extractedNumber', extractedNumberr1]);


Hi! I have a problem with the embedded data from an intercept in a web survey. We never had this problem but now it is real.

I used Java script and I entered it like this: google_tag_managerr"GTM-MJSJH6Z"].dataLayer.get('userId')

We didt it with simple quotes and with double quotes but neither of them haven`t worked

 

 

Also, I mapped the variable in the survey like this:

 

However, I can’t see the variable in the responses, I only see “undefined”:

 

 


Leave a Reply