I want to capture substring of embedded data field referral URL

I want to capture substring of embedded data field referral URL


Our client wants to be able to capture the referral URL that takes them to our survey. We have set the embedded data field in our survey flow to do this and this is working fine

However, most important within this URL is a substring with a finite number of variations (max 20) that they want to see. Whereas each URL that a customer sees will be unique, this substring will not be. In this instance the only part of the url I need is "secure-logout-XX"

How do I set up the embedded data field to only return this substring? I have some javascript (i doubt it is perfect ...) that will return the substring, but I'm not sure where to put it? Is it even possible?

(Although the url will have to be the original embedded data field that has been captured in the survey flow )

f = function(){
var url = 'https://www.CLIENT.com/secure-logout-XX...' // this will actually be the Survey Metadata referer value and not hardcoded
var ref = url.substring(23, 39);
if (url != null){
return ref;}
else {
return ref;}

Best Answer

  • TomGTomG Raleigh, NC Wizard ✭✭✭✭✭
    edited March 2018 Accepted Answer

    Create an embedded data variable secure-logout-XX in your survey flow. Then add your JavaScript to a question where you pipe in the value of the url into a string, then set the value of the secure-logout-XX variable to the string returned by your JavaScript. I've attached a file with the two applicable lines changed.


Sign In to Comment