Google DFP: transfer UTM_Source to DFP using javascript (without access to DFP administrator)

I am looking for a way to grab the utm_source value from a URL using javascript and pass it to Google DFP, which does not require setting anything in Admin DFP (for example, targeting for key values) t have access to the admin panel for a specific site with which we are working.

Thank you for the tips / javascript.

0
source share
1 answer

Use setTargetting. You will need to open the "Resources" tab on the DFP toolbar to create utm code keys ( link to key values )

<script>

    function getParameterByName(name, url) {
        if (!url) url = window.location.href;
        name = name.replace(/[\[\]]/g, "\\$&");
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
            results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\+/g, " "));
    }

    googletag.cmd.push(function () {
        googletag.pubads().setTargeting('utm_source', getParameterByName('utm_source'));
    });

</script>
0
source

Source: https://habr.com/ru/post/1686128/


All Articles