Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add functions to create and delete custom targeting keys and values #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 103 additions & 2 deletions examples/customTargetingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,31 @@ dfpUser.setSettings(dfpConfig);
dfpUser.getService('CustomTargetingService', (err, targetingService) => {
if (err) throw err;


//create customTargetingKeys
createCustomTargetingKeys(targetingService, (err, result) => {
if (err) throw err;
console.log(result);
//expected result:

// {
// "rval": {
// "totalResultSetSize": 1,
// "startIndex": 0,
// "results": [
// {
// "id": "123456789",
// "name": "AB",
// "displayName": "ABE",
// "type": "FREEFORM",
// "status": "ACTIVE"
// }
// ]
// }
// }
});


//get customTargetingKeys
getCustomTargetingKeys(targetingService, (err, result) => {
if (err) throw err;
Expand Down Expand Up @@ -51,6 +76,32 @@ dfpUser.getService('CustomTargetingService', (err, targetingService) => {
// "status": "ACTIVE"
// }
// ]
// }
});


//create customTargetingValues
createCustomTargetingValues(targetingService, (err, result) => {
if (err) throw err;
console.log(result);

//expected result:

// {
// "rval": {
// "totalResultSetSize": 1,
// "startIndex": 0,
// "results": [
// {
// "customTargetingKeyId":"123456789",
// "id": "1234567897384",
// "name": "DCE",
// "displayName": "DC",
// "matchType":"EXACT",
// "status": "ACTIVE"
// }
// ]
// }
// }
})

Expand Down Expand Up @@ -79,7 +130,7 @@ dfpUser.getService('CustomTargetingService', (err, targetingService) => {
// }
// }

})
});

//updateCustomTargetingValues
updateCustomTargetingValues(targetingService, (err, result) => {
Expand All @@ -98,11 +149,48 @@ dfpUser.getService('CustomTargetingService', (err, targetingService) => {
// "status": "ACTIVE"
// }
// ]
// }
});

performCustomTargetingValue(targetingService, (err, result) => {
if (err) throw err;
console.log(result);

//expected result:

// {
// {"rval": {"numChanges":1}}
// }
})

});

let createCustomTargetingKeys = (targetingService, done) => {
var args = { keys: [{
"name":"AB",
"displayName": "ABE"
"type":"FREEFORM",
"status":"ACTIVE"}
]};
targetingService.createCustomTargetingKeys(args, (err, results) => {
if (err) throw err;
done(null, results);
})
}

let createCustomTargetingValues = (targetingService, done) => {
var args = { values: [{
"customTargetingKeyId":"123456789",
"name": "DCE",
"displayName": "DC",
"status":"ACTIVE"}
]};
targetingService.createCustomTargetingValues(args, (err, results) => {
if (err) throw err;
done(null, results);
})
}


let getCustomTargetingKeys = (targetingService, done) => {
let query = new Dfp.Statement("WHERE status='ACTIVE'");//put your query statement
Expand Down Expand Up @@ -140,7 +228,7 @@ let updateCustomTargetingKeys = (targetingService, done) => {

let updateCustomTargetingValues = (targetingService, done) => {
var args = { values: [{
"customTargetingKeyId":"11704510",
"customTargetingKeyId":"123456789",
"id":"1234567897384",
"name":"DCERZ",
"displayName":"DCERZT",
Expand All @@ -152,3 +240,16 @@ let updateCustomTargetingValues = (targetingService, done) => {
done(null, results);
})
}

let performCustomTargetingValue = (targetingService, done) => {
let args = {
customTargetingValueAction: {
attributes: { 'xsi:type': 'DeleteCustomTargetingValues' }
},
filterStatement: { query: "WHERE customTargetingKeyId= 11817015 AND name LIKE 'DCERZ'"}
};
targetingService.performCustomTargetingValueAction(args, (err, results) => {
if (err) throw err;
done(null, results);
})
}