Append UTMs upon DOM change

Here is an example of snippet you can use to append UTMs upon a DOM change. This requires advance coding skills.

setTimeout(function(){ 

var target = document.querySelector('#storepoint-results')
var observer = new MutationObserver(function(mutations) {
	console.log(jQuery(target).find('.storepoint-onlinestore').length)
  if ( jQuery(target).find('.storepoint-onlinestore').length > 0 ){
  	var a = jQuery(target).find('.storepoint-onlinestore')
  	var target_url = a.attr('href')
  	var merged = jQuery.extend( {}, handl_utm, getSearchParams(target_url) )
  	var src = target_url.split("?")[0];
  	if ( !jQuery.isEmptyObject(merged) ){
    	var final_target = src + "?" + jQuery.param(merged)
    }
    a.attr('href', final_target)
  }
});
var config = { attributes: true, childList: true, characterData: true };
observer.observe(target, config);

 }, 500);

Revision #1
Created Sat, May 15, 2021 2:55 AM by Leman
Updated Sat, May 15, 2021 2:56 AM by Leman