Is there a way to add (not include) a query string parameter on the URL from the target. | Community
Skip to main content
Adobe Employee
November 2, 2021
Solved

Is there a way to add (not include) a query string parameter on the URL from the target.

  • November 2, 2021
  • 2 replies
  • 2211 views

Use case is as follows:

 

Created an activity with the expectation where in 50% of the users see the experience where the video automatically plays when user lands on the page whereas 50% of the users should click on the play button. User looked for the possible ways and found there are 2 ways to to implement auto play, in general and not specifically to target:
1. Add code directly at the page level.
2. To add (not include) parameter in the URL.
 
The question here is - 
Is there a way to add a query string parameter on the URL from the target.
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Gaureshk_Kodag

Hi @mayurik 

 

You can use custom code option in VEC. Add custom javascript to append query parameters in the URL. you can use following JS code.

function insertParam(key, value) {
key = encodeURIComponent(key);
value = encodeURIComponent(value);

// kvp looks like ['key1=value1', 'key2=value2', ...]
var kvp = document.location.search.substr(1).split('&');
let i=0;

for(; i<kvp.length; i++){
if (kvp[i].startsWith(key + '=')) {
let pair = kvp[i].split('=');
pair[1] = value;
kvp[i] = pair.join('=');
break;
}
}

if(i >= kvp.length){
kvp[kvp.length] = [key,value].join('=');
}

// can return this or...
let params = kvp.join('&');

// reload page with new params
document.location.search = params;
}

query.append("test","true");

 

let me know if this works.

 

 

2 replies

Gaureshk_Kodag
Adobe Employee
Gaureshk_KodagAdobe EmployeeAccepted solution
Adobe Employee
November 2, 2021

Hi @mayurik 

 

You can use custom code option in VEC. Add custom javascript to append query parameters in the URL. you can use following JS code.

function insertParam(key, value) {
key = encodeURIComponent(key);
value = encodeURIComponent(value);

// kvp looks like ['key1=value1', 'key2=value2', ...]
var kvp = document.location.search.substr(1).split('&');
let i=0;

for(; i<kvp.length; i++){
if (kvp[i].startsWith(key + '=')) {
let pair = kvp[i].split('=');
pair[1] = value;
kvp[i] = pair.join('=');
break;
}
}

if(i >= kvp.length){
kvp[kvp.length] = [key,value].join('=');
}

// can return this or...
let params = kvp.join('&');

// reload page with new params
document.location.search = params;
}

query.append("test","true");

 

let me know if this works.

 

 

MayuriKAdobe EmployeeAuthor
Adobe Employee
November 2, 2021

Hi @gaureshk_kodag 

 

Thanks for the information. But here we are creating form based activity and trying to create an html offer to add parameter to the URL.

 

How can we do that in case of form based activity. 

 

Current implementation is as follows:

HTML offer code:

setTimeout(()=>{
let videoAutoPlay = document.querySelector('video-js');
videoAutoPlay.player.muted(true);
videoAutoPlay.player.play();
},1000);

 

I am not sure if this is the correct way.

Gaureshk_Kodag
Adobe Employee
Adobe Employee
November 3, 2021

Hi @mayurik ,

Just add the code which I shared earlier after your code. It'll work in for based as well.

Also, im not sure if @mihnead's solution will work for you cause you have your own code to run as well. So using redirect offer might not work here. Please correct me if im wrong @mihnead 

 

Thanks.

MihneaD
Adobe Employee
Adobe Employee
November 2, 2021

@mayurik,

 

If you are still searching for alternatives it would also be possible to accomplish this via a redirect:

ExpA: Default
ExpB: Redirect from url1.com --to--> url1.com/?playnowparameter

The only caveat is you have to test to validate you aren't setting up an infinite redirect loop. If the activity is configured to allow access only from url1.com it should work however if it's configured to allow access from url that contains url1 it will result in an infinite redirect loop. Hope this helps.

 

--Docea

MayuriKAdobe EmployeeAuthor
Adobe Employee
November 3, 2021

This method cannot be used as there is not one url where we need auto play functionality. There are multiple page URL

Gaureshk_Kodag
Adobe Employee
Adobe Employee
November 3, 2021

Oh okay. I believe using code which I shared should resolve your problems.