Parse URL Parameters

Avatar

Avatar
Validate 25
Level 4
alim92960278
Level 4

Likes

37 likes

Total Posts

103 posts

Correct reply

5 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile

Avatar
Validate 25
Level 4
alim92960278
Level 4

Likes

37 likes

Total Posts

103 posts

Correct reply

5 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Boost 5
Boost 3
View profile
alim92960278
Level 4

29-10-2015

I would appreciate any help with this:

I know how to parse a URL parameter and populate a traffic variable with the value using a data element, but In some cases I only want part of the value.

I'm capturing full URLs in prop2: document.location.hostname+document.location.pathname+document.location.search

  • Example URL: "www.example.com?vanity_url=website.com-spring"
  • Desired outcome: sprop8="spring"

Ali

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 10
Level 10
ParitMittal
Level 10

Likes

93 likes

Total Posts

817 posts

Correct reply

349 solutions
Top badges earned
Validate 10
Validate 1
Boost 50
Boost 5
Boost 3
View profile

Avatar
Validate 10
Level 10
ParitMittal
Level 10

Likes

93 likes

Total Posts

817 posts

Correct reply

349 solutions
Top badges earned
Validate 10
Validate 1
Boost 50
Boost 5
Boost 3
View profile
ParitMittal
Level 10

17-12-2015

Hi Ali,

As per the above Scenario , It will be required to use some ready made Javascript  string functions  . Assuming that the URL parameter vanity_url, will always have a special character "-" before the value that needs to be captured in a prop variable , we can use the below piece of code: 

Var vanity_ur= s.utility.getQueryParam('vanity_url');

Var index= vanity_ur.lastIndexOf("-"),

Var length=vanity_ur.length;

Var val= vanity_ur.substring(index, length);

s.prop8=val;

Please let us know if you have any questions or queries.

Thanks & Regards

Parit Mittal

Answers (0)