Skip to main content

Using Same Location for Product Search and Campaign Working Location

How can we copy Location user enters on "Let's target the right talent" form to be used on Working Location of Campaign Form on Working Location step of Order Journey?

User already enters a Location on Let's target the right talent form which is the search-recommend-products (formerly called onboarding) step for searching products, however that does not necessarily mean that the user will be using the same country/city for the working location for the campaign they will order.


User may enter Europe to get best performing channels but enter Netherlands to the Working Locations's country of the campaign, therefore we don't want to make that opinion on behalf of the end user, but you can programmatically copy the Location entered in the search form to the campaign's working location's country and city field as such:

caution

The Location field on product search accepts multiple values thus the below code may produce unreliable results, thus we don't recommend doing this copying behavior.

An example is:

  • User enters Istanbul, Türkiye
  • User enters Germany

The Working Location will have:

  • Country: Germany
  • City: Istanbul

Istanbul is not in Germany.

const selectedJobRegionsIds = window.hapi.product.state.jobRegionsIdsSelected.value

const copyLocationFromSearchToWorkingLocationCountryAndCity = (jobRegionIds) => {
const jobRegions = window.hapi.product.state.jobRegions.value

// because user may select multiple locations in product search
// if user enters two city or two country values
// then the last one in the array will overwrite the below values
let countryToCopy = ""
let cityToCopy = ""

jobRegionIds.forEach(jobRegionId => {
const jobRegion = jobRegions.find(region => region.id === jobRegionId)
if (jobRegion) {
if (jobRegion.place_type.includes("country")) {
countryToCopy = jobRegion.canonical_name
} else if (jobRegion.place_type.includes("place")) {
cityToCopy = jobRegion.canonical_name
}
}
})

window.hapi.campaign.state.campaignForm = window.hapiUtils.mergeDeepOverwriteArrays(
window.hapi.campaign.state.campaignForm.value,
{
postingDetails: {
workingLocation: {
country: countryToCopy,
city: cityToCopy
}
}
}
)
}

copyLocationFromSearchToWorkingLocationCountryAndCity(selectedJobRegionsIds)

In most cases you would want to run the above code every time user changes the Location in the search-recommend-products step. You can do that as such:

window.hapi.product.state.jobRegionsIdsSelected.onChange((jobRegionsIds) => {
copyLocationFromSearchToWorkingLocationCountryAndCity(jobRegionsIds)
})