Dynamic content based on URL parameter

Robb_Barrett
Marketo Employee

Re: Dynamic content based on URL parameter

This might help:

The first function will pull down the value of any URL parameter you request.

function getUrlParameter(sParam)

{

    sPageURL=window.location.search.substring(1);

    var sURLVariables = sPageURL.split('&');

    for (var i = 0; i < sURLVariables.length; i++)

    {

       var sParameterName = sURLVariables[i].split('=');

       if (sParameterName[0].toLowerCase() == sParam.toLowerCase())

           return sParameterName[1];

    }

    return "";

}

var company = decodeURI(getUrlParameter("company")); //*this removes the HTML codes

function getCompanyLogo(compName) { 

var image=""; 

if (/[?&]campaignID=/.test(location.href) == false)  {  //*this tests to see if the parameter exists

    image = "http://www.path-to-default.com/image.jpg";  //*use default image

  } else {

  if (compName== "company1") {

     image = "http://path-to-image.com/company1.jpg";

} else {

     if(compName== "company2") {

     image = "http://path-to-image.com/company1.jpg";

} else {

....

}  //*close company name loop

} //*close top level test

return image; //*sends back the correct URL

var image = document.createElement("img");  //*create an image DOM
image.setAttribute("src", getCompanyLogo(company)); //*Set the image as the URL selected
document.getElementById("your-empty-div").appendChild(image); //*Put the image in the DIV

Robb Barrett
SanfordWhiteman
Level 10 - Community Moderator

Re: Dynamic content based on URL parameter

Robb, you don't need any JS for a dynamic (temporary) segmentation. The URL is parsed on the server.

(Also, that JS will break on some well-formed URLs, but that's another issue.)

Ronen-Was-SRpro
Level 7

Re: Dynamic content based on URL parameter

Hi,

Is it possible to show a form in a landing page that will be changed to different languages according to the URL? For example, if the user has www.goog.com/EN

He will be shown the form in English or if the user has www.goog.com/ES he will see the same form in Spanish.

Thank you.

Ronen Wasserman
SanfordWhiteman
Level 10 - Community Moderator

Re: Dynamic content based on URL parameter

The question is more about whether a single form can dynamically change languages at all. And the answer is: it can't, unless you use the Forms API (we've done this to create a single internationalized form, but it's not simple).

If you have multiple forms (different Form IDs) already separated by language, then Yes: that can be part of Dynamic Content and in turn can be selected by passing ?{Segmentation}={Segment} in the URL.