简体   繁体   中英

Google DFP: Pass UTM_Source to DFP with javascript (without accessing the DFP Admin)

I'm looking for a way to grab the utm_source value from a URL with javascript and pass it to Google DFP, which doesn't involve configuring anything in the DFP Admin (such as key-value targeting) as we don't have access to the admin panel for the specific site we are working with.

Would appreciate any tips / javascript code.

Use setTargetting. You will need to access the Inventory tab in DFP's dashboard to create the utm code keys ( Key-values link )

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM