Skip to main content
Contributor II
February 17, 2022
Solved

Javascript API to update a Custom property with a url parameter

  • February 17, 2022
  • 1 reply
  • 343 views

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 !

    This topic has been closed for replies.
    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!

    1 reply

    stephen.trumble
    Klaviyo Alum
    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!

    -Stephen