Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

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

MayuriK
Level 2
Level 2

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.
1 Accepted Solution
gaureshk3014423
Correct answer by
Level 9
Level 9

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.

 

 

View solution in original post

6 Replies
gaureshk3014423
Correct answer by
Level 9
Level 9

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.

 

 

View solution in original post

MayuriK
Level 2
Level 2

Hi @gaureshk3014423 

 

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.

gaureshk3014423
Level 9
Level 9

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 @Docea'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 @Docea 

 

Thanks.

Docea
Employee
Employee

@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

MayuriK
Level 2
Level 2

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

gaureshk3014423
Level 9
Level 9

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