Skip to content

Instantly share code, notes, and snippets.

@fIa5h
fIa5h / AMI_NR.js
Last active April 22, 2020 17:05
Ryan & Bruce
/*
New Relic GPT ad monitoring code
//
This snippet captures PageActions containing references to Google publisher tag ads
Should you have any questions about this, please reach out to me at rmusser@newrelic.com
Please note that you must be using New Relic's SPA browser agent.
//
*/
//
//first, make sure the newrelic object exists properly
var nr_monitor_ads = function(){
var convertToString = ['advertiserId', 'campaignId', 'creativeId', 'lineItemId', 'labelIds', 'sourceAgnosticCreativeId', 'sourceAgnosticLineItemId'];
var NR_SUBMIT_PAGE_ACTION = function(ev, obj) {
if (typeof window.newrelic != 'undefined' && typeof window.newrelic.addPageAction == 'function') {
for (i in obj) {
if (convertToString.indexOf(i) > -1) {
obj[i] = String(obj[i]);
}
}
window.newrelic.addPageAction(ev, obj)