I am implement in AnguarJs application and use Javascript so please help me how to pass dynamic url (page name) in our code.
<script>
window.googletag = window.googletag || { cmd: [] };
googletag.cmd.push(function () {
var pathname = window.parent.location.pathname;
var length = 40;`enter code here`
var url = pathname.substring(1, length).replace(/[!@#$%^&*/()_-]/g, "");
googletag.defineSlot('/14616973/cbcs_dt_1_728x90_1', [728, 90], 'div-gpt-ad-1604917677506-1').addService(googletag.pubads());
googletag.defineSlot('/14616973/cbcs_dt_2_728x90_2', [728, 90], 'div-gpt-ad-1604917677506-2').addService(googletag.pubads());
googletag.defineSlot('/14616973/cbcs_dt_3_300x250_1', [300, 250], 'div-gpt-ad-1604917677506-3').addService(googletag.pubads());
googletag.defineSlot('/14616973/cbcs_dt_4_300x600_1', [300, 600], 'div-gpt-ad-1604917677506-4').addService(googletag.pubads());
googletag.defineSlot('/14616973/cbcs_mb_1_300x250_1', [300, 250], 'div-gpt-ad-1604918658528-1').addService(googletag.pubads());
googletag.defineSlot('/14616973/cbcs_mb_1_300x250_2', [300, 250], 'div-gpt-ad-1604918658528-2').addService(googletag.pubads());
googletag.defineSlot('/14616973/cbcs_mb_3_300x600_3', [300, 600], 'div-gpt-ad-1604918658528-3').addService(googletag.pubads());
googletag.pubads().setTargeting('Sub_Category', []).setTargeting('Cat', []).setTargeting('url', [url]).setTargeting('search', []).setTargeting('Page', []);
googletag.pubads().collapseEmptyDivs();
googletag.enableServices();
});
</script>
As detailled here, if your key has a single value, you should send a string :
var pathname = window.parent.location.pathname;
var length = 40;
var url = pathname.substring(1, length).replace(/[!@#$%^&*/()_-]/g, "");
..
googletag.pubads().setTargeting('url', url);
To be able to target a specific page, you could also pass the page or content ID to GPT : it avoids having duplicates as the 40 caracters length limitation for values might end up with similar value for different pages... (it depends on the way your page URLs are built).