Solved

Javascript API to update a Custom property with a url parameter

  • 17 February 2022
  • 1 reply
  • 289 views

Badge +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 !

icon

Best answer by stephen.trumble 18 February 2022, 12:24

View original

1 reply

Userlevel 7
Badge +60

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!

Reply