Skip to main content
Solved

Javascript API to update a Custom property with a url parameter

  • February 17, 2022
  • 1 reply
  • 318 views

Forum|alt.badge.img+2
  • Contributor II
  • 3 replies

Hi there,

 

I’m trying to build a tag that will update a custom property with a url parameter.
The url parameter is locale=XX where XX is the value to use as custom property.

Here is the code… I'm not a developer so I'm really not sure if this code is developed as desired... what do you think ?

 

<script>

  var _learnq = _learnq || [];

// Define var locale from url parameter

var str = document.location.href;

var url = new URL(str);

var search_params = new URLSearchParams(url.search); 

if(search_params.has('locale')) {

  var language = search_params.get('locale');

}

// Identifying a person and tracking special Klaviyo properties.

  _learnq.push(['identify', {

    '$email' : '',

    'language' : language

  }]);

</script>

 

Thanks a lot for the help !

Best answer by stephen.trumble

Hey @mdh 

Thank you so much for coming to the Klaviyo Community for help!

If you need help with some personal coding for your site, you can contact one of our Agency Partners to get develop this out!

View original
Did this topic or the replies in the thread help you find an answer to your question?

1 reply

stephen.trumble
Community Manager
Forum|alt.badge.img+60
  • Community Manager
  • 1518 replies
  • Answer
  • February 18, 2022

Hey @mdh 

Thank you so much for coming to the Klaviyo Community for help!

If you need help with some personal coding for your site, you can contact one of our Agency Partners to get develop this out!