├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── core_functionality ├── appsscript.json ├── main.js ├── python_parser.js ├── spreadsheet_reader.js └── tracking.js └── extra_functionality ├── CustomBiddingRedirect.html ├── appsscript.json ├── on_open.js └── tracking.js /.gitignore: -------------------------------------------------------------------------------- 1 | */.clasp.json 2 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement (CLA). You (or your employer) retain the copyright to your 10 | contribution; this simply gives us permission to use and redistribute your 11 | contributions as part of the project. Head over to 12 | to see your current agreements on file or 13 | to sign a new one. 14 | 15 | You generally only need to submit a CLA once, so if you've already submitted one 16 | (even if it was for a different project), you probably don't need to do it 17 | again. 18 | 19 | ## Code Reviews 20 | 21 | All submissions, including submissions by project members, require review. We 22 | use GitHub pull requests for this purpose. Consult 23 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 24 | information on using pull requests. 25 | 26 | ## Community Guidelines 27 | 28 | This project follows 29 | [Google's Open Source Community Guidelines](https://opensource.google/conduct/). -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Custom Bidding Script Builder 2 | 3 | **Create Custom Bidding scripts without writing any Python** 4 | 5 | 6 | ## Context 7 | 8 | Expressing a DV360 Custom KPI that correlates with real business outcomes is technically complex and typically requires knowledge of Python to construct scripts. 9 | 10 | This barrier to entry prevents its target user base from being able to utilize DV360 Custom Bidding to express complex KPIs and leverage the additional functionality only unlocked by scripts. 11 | 12 | This solution will allow users to input values into a Sheets-based UI and the solution will deliver a fully executable Custom Bidding script. 13 | 14 | 15 | ## Deployment 16 | 17 | 1. Join the [Google group](https://groups.google.com/g/cb-script-builder-users) 18 | 2. Make a copy of the [spreadsheet template](https://docs.google.com/spreadsheets/d/1mwM5tLJU_nMJhTMfAsAZOtIxYBDwiwYX_OA_ELi52sA/edit?usp=drive_open&ouid=112421620903932810067&resourcekey=0-Jpkcbu8GZMs2MiMz3RB-zw) 19 | 3. Grant view access to cb-script-builder@google.com (recommended) 20 | 4. Authorize the tool when prompted (after first function run) 21 | * If you receive a warning that the app isn't verified, see User Guide for more info 22 | 23 | 24 | ## Resources 25 | 26 | * [Script Builder User Guide](https://docs.google.com/presentation/d/1_PTs5abxOVK5wuwfcJ-FZttqfmJM2BzyLTd0ljK2rHg/edit#slide=id.g17c910c370d_0_0)** 27 | * Script Builder Overview 28 | * Sample Use Case & Workflow 29 | * Deployment Instructions 30 | * Custom Bidding Resources 31 | * [Script Builder Spreadsheet Template](https://docs.google.com/spreadsheets/d/1mwM5tLJU_nMJhTMfAsAZOtIxYBDwiwYX_OA_ELi52sA/edit?usp=drive_open&ouid=112421620903932810067&resourcekey=0-Jpkcbu8GZMs2MiMz3RB-zw)** 32 | * [Script Builder Video Demos](https://www.youtube.com/@DV3CustomBiddingScriptBuilder) 33 | * [Instructions to Add Script in DV360 UI](https://support.google.com/displayvideo/answer/9728993?hl=en&ref_topic=11967792#zippy=:~:text=choose%C2%A0Create.-,Create%20your%20script,-Note%3A) 34 | * [Sample Custom Bidding Scripts](https://support.google.com/displayvideo/answer/11968381?hl=en&ref_topic=11967792#zippy=) 35 | 36 | \** Must join the [Google group](https://groups.google.com/g/cb-script-builder-users) to access 37 | 38 | 39 | ## License 40 | 41 | **This is not an officially supported Google product.** 42 | 43 | Copyright 2023 Google LLC. This solution, including any related sample code or data, is made available on an "as is", "as available", and "with all faults" basis, solely for illustrative purposes, and without warranty or representation of any kind. This solution is experimental, unsupported and provided solely for your convenience. Your use of it is subject to your agreements with Google, as applicable, and may constitute a beta feature as defined under those agreements. To the extent that you make any data available to Google in connection with your use of the solution, you represent and warrant that you have all necessary and appropriate rights, consents and permissions to permit Google to use and process that data. By using any portion of this solution, you acknowledge, assume and accept all risks, known and unknown, associated with its usage, including with respect to your deployment of any portion of this solution in your systems, or usage in connection with your business, if at all. 44 | -------------------------------------------------------------------------------- /core_functionality/appsscript.json: -------------------------------------------------------------------------------- 1 | { 2 | "timeZone": "Europe/Vienna", 3 | "exceptionLogging": "STACKDRIVER", 4 | "oauthScopes": [ 5 | "https://www.googleapis.com/auth/spreadsheets.currentonly", 6 | "https://www.googleapis.com/auth/userinfo.email" 7 | ], 8 | "runtimeVersion": "V8" 9 | } 10 | 11 | -------------------------------------------------------------------------------- /core_functionality/main.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyrigh 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Opens a dialogue box with the JSON inputs formatted to be more readable to 19 | * non-tech users. Triggered via the "QA Script" button in the UI. Also 20 | * includes error handling and tracking. 21 | */ 22 | function printJSON() { 23 | try { 24 | let finalJSON = { 25 | 'PartnerID': PARTNER_ID, 26 | 'AdvertiserID': ADVERTISER_ID, 27 | 'AggregationMethod': AGGREGATION_METHOD, 28 | 'ExpressionWeightPairs': getConditions() 29 | }; 30 | SpreadsheetApp.getUi().alert( 31 | JSON.stringify(finalJSON, null, '\u{2000}'.repeat(2))); 32 | logFunctionRun('Print JSON'); 33 | } catch (err) { 34 | Browser.msgBox('ERROR', err.message, Browser.Buttons.OK); 35 | logFunctionRun('Print JSON', err); 36 | } 37 | } 38 | 39 | /** 40 | * Opens a dialogue box with final Custom Bidding python script which can be 41 | * copied to DV3 UI. Triggered via the "Final Script to Copy" button in the UI. 42 | * Also includes error handling and tracking. 43 | */ 44 | function printScript() { 45 | try { 46 | let conditions = getConditions(); 47 | let pythonScript = convertToPythonScript(conditions); 48 | logFunctionRun('Print Script'); 49 | Browser.msgBox(pythonScript); 50 | } catch (err) { 51 | logFunctionRun('Print Script', err); 52 | Browser.msgBox('ERROR', err.message, Browser.Buttons.OK); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /core_functionality/python_parser.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Parses a JSON object into a simple Python script that is compatible with 19 | * DV360 Custom Bidding 20 | * @param {[condition]} conditions Array of weight and expression dictionaries 21 | * @return {string} 22 | */ 23 | function convertToPythonScript(conditions) { 24 | let finalScript = ''; 25 | let aggregationMethod = AGGREGATION_METHOD; 26 | let expressionsObj = conditions; 27 | let expressionWeightString = ''; 28 | for (let criteria of expressionsObj) { 29 | let expression = Object.keys(criteria)[0]; 30 | let weight = Object.values(criteria)[0]; 31 | expressionWeightString += `([${expression}], ${weight}),\\n`; 32 | } 33 | finalScript += 34 | `return ${aggregationMethod} ([ \\n${expressionWeightString} 35 | #Created with CB Script Builder \\n])`; 36 | return finalScript; 37 | } 38 | -------------------------------------------------------------------------------- /core_functionality/spreadsheet_reader.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @OnlyCurrentDoc 19 | */ 20 | 21 | /** Global Variables */ 22 | const ss = SpreadsheetApp.getActiveSpreadsheet(); 23 | const sheet = ss.getActiveSheet(); 24 | 25 | /** Spreadsheet Layout */ 26 | const globalInputsColumn = 2; 27 | const partnerIdRow = 2 28 | const advertiserIdRow = partnerIdRow + 1; 29 | const aggregationModelRow = partnerIdRow + 2; 30 | const firstConditionRow = 8; 31 | const weightingColumn = 2; 32 | const conditionStartColumn = 4; 33 | const clauseWidth = 6; 34 | 35 | /** Create constants for User Input Values */ 36 | const PARTNER_ID = 37 | sheet.getRange(partnerIdRow, globalInputsColumn).getDisplayValue(); 38 | const ADVERTISER_ID = 39 | sheet.getRange(advertiserIdRow, globalInputsColumn).getDisplayValue(); 40 | const AGGREGATION_METHOD = 41 | sheet.getRange(aggregationModelRow, globalInputsColumn).getDisplayValue(); 42 | 43 | /** 44 | * Creates error object for user input errors 45 | * @param {string} message The error message to display to the user 46 | */ 47 | function UserInputError(message) { 48 | this.message = message; 49 | this.name = 'UserInputError'; 50 | } 51 | 52 | UserInputError.prototype = Error.prototype; 53 | 54 | /** 55 | * A dictionary object to store the conditions and weights 56 | * @typedef {Object.} condition 57 | * @property {string} Expression The logical expression used as a condition 58 | * @property {string} Weight The weight assigned to the condition 59 | */ 60 | 61 | 62 | /** 63 | * Creates an array of dictionaries with weight as the value and the boolean 64 | * expression as the key SAMPLE OUTPUT: 65 | * [{ 'active_view_viewed and time_on_screen_seconds>10 and 66 | * creative_height>300': '100' }, { 'active_view_viewed and 67 | * creative_height>300': '70' }, { 'active_view_viewed and 68 | * time_on_screen_seconds>10': '40' }] 69 | * @return {[condition]} The array of weight and expression dictionaries 70 | */ 71 | function getConditions() { 72 | let conditionRow = firstConditionRow; 73 | let weight = 74 | sheet.getRange(firstConditionRow, weightingColumn).getDisplayValue(); 75 | if (weight == '') { 76 | throw new UserInputError( 77 | 'There are not enough inputs to make a valid script'); 78 | }; 79 | let conditions = []; 80 | while (weight != '') { 81 | let expression = constructExpression(conditionRow); 82 | if (expression == '') { 83 | Browser.msgBox( 84 | 'WARNING', 85 | 'One of your weights has been assigned to an empty condition. This will assign that weight to any impression where the other conditions are not met. \\n \\n Please carefully check your code to ensure this is intended behavior.', 86 | Browser.Buttons.OK); 87 | } 88 | dict = {}; 89 | dict[expression] = weight; 90 | conditions.push(dict); 91 | conditionRow += 1; 92 | weight = sheet.getRange(conditionRow, weightingColumn).getDisplayValue(); 93 | } 94 | return conditions; 95 | } 96 | 97 | /** 98 | * Creates a condition string that evaluates to a boolean expression for each 99 | * row of the spreadsheet 100 | * SAMPLE INPUT (Brackets used to represent cells): 101 | * [active_view_viewed] [==] [TRUE] [] [AND] [] [creative_height] [>] [300] 102 | * SAMPLE OUTPUT: 'active_view_viewed and creative_height>300' 103 | * @param {number} rowNumber The number of the row from which the boolean 104 | * expression is built 105 | * @return {string} 106 | */ 107 | function constructExpression(rowNumber) { 108 | let expression = ''; 109 | let conditionColumn = conditionStartColumn; 110 | let variable = sheet.getRange(rowNumber, conditionColumn).getDisplayValue(); 111 | /**Checks if there is another clause in the row to be added to final 112 | * expression */ 113 | while (variable != '') { 114 | let operator = 115 | sheet.getRange(rowNumber, conditionColumn + 1).getDisplayValue(); 116 | let value = 117 | sheet.getRange(rowNumber, conditionColumn + 2).getDisplayValue(); 118 | /** Adds a clause to the expression */ 119 | clause = constructClause(variable, operator, value); 120 | if (clause == '') { 121 | throw new UserInputError( 122 | `One of your clauses is missing an input and therefore invalid. 123 | Please check row number ${ 124 | rowNumber} and correct the error before retrying.`); 125 | } 126 | expression += clause; 127 | /**Moves to the next possible instance of a clause and redefines "variable" 128 | */ 129 | conditionColumn += clauseWidth; 130 | variable = sheet.getRange(rowNumber, conditionColumn).getDisplayValue(); 131 | /**Adds a connector only if there is an additional clause coming after */ 132 | if (variable != '') { 133 | let connector = 134 | sheet.getRange(rowNumber, conditionColumn - 2).getDisplayValue(); 135 | if (connector == '') { 136 | throw new UserInputError( 137 | `Check your inputs: One of your conditions is missing a logical connector and therefore invalid. 138 | Please check row number ${ 139 | rowNumber} and correct the error before retrying.`); 140 | } 141 | connector = connector.toLowerCase(); 142 | expression += (' ' + connector + ' '); 143 | } 144 | } 145 | return expression; 146 | } 147 | 148 | /** 149 | * Constructs a single criteria clause and checks for incorrectly empty values 150 | * @param {string} variable The DV360 variable we are evaluating against a 151 | * criteria (e.g. creative_height) 152 | * @param {string} operator The operator used to evaluate the criteria (e.g. == 153 | * or >) 154 | * @param {string} value The criteria value (in most cases this is either a 155 | * boolean or an integer stored as a string - e.g. "True" or "300") 156 | * @return {string} 157 | */ 158 | function constructClause(variable, operator, value) { 159 | let clause = ''; 160 | /** For simplicity, "variable == True" is simplified to just "variable" */ 161 | if (value.toLowerCase() == 'true') { 162 | clause = variable; 163 | } else if (value.toLowerCase() == 'false') { 164 | /** Ensures that any capitalization of False is converted to proper case */ 165 | value = 'False'; 166 | clause = variable + '==' + value; 167 | } else { 168 | if (operator == '' || value == '') { 169 | return ''; 170 | } 171 | clause = variable + operator + value; 172 | } 173 | return clause; 174 | } 175 | -------------------------------------------------------------------------------- /core_functionality/tracking.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Writes data to the tracking sheet based on what function was run and whether 19 | * or not it triggered an error 20 | * @param {string} functionName The name of the function being executed 21 | * @param {Object=} err The error object 22 | */ 23 | 24 | function logFunctionRun(functionName, err) { 25 | let ss = SpreadsheetApp.getActiveSpreadsheet(); 26 | let sheet = ss.getSheetByName('Error Tracking'); 27 | let ss_id = SpreadsheetApp.getActiveSpreadsheet().getId(); 28 | let partner_id = PARTNER_ID; 29 | let adv_id = ADVERTISER_ID; 30 | let user = Session.getActiveUser().getEmail(); 31 | let status = ''; 32 | if (err == undefined) { 33 | error = ''; 34 | status = 'Success'; 35 | } else { 36 | error = err.message; 37 | status = err.name; 38 | }; 39 | ss.setSpreadsheetTimeZone(Session.getScriptTimeZone()); 40 | let ts = new Date(); 41 | sheet.appendRow( 42 | [ts, ss_id, partner_id, adv_id, user, functionName, status, error]); 43 | } 44 | -------------------------------------------------------------------------------- /extra_functionality/CustomBiddingRedirect.html: -------------------------------------------------------------------------------- 1 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 28 | 29 | Please allow this window to create pop ups
30 | Or Click Here to continue 31 | 32 | 33 | -------------------------------------------------------------------------------- /extra_functionality/appsscript.json: -------------------------------------------------------------------------------- 1 | { 2 | "timeZone": "Europe/Vienna", 3 | "exceptionLogging": "STACKDRIVER", 4 | "oauthScopes": [ 5 | "https://www.googleapis.com/auth/spreadsheets.currentonly", 6 | "https://www.googleapis.com/auth/script.container.ui", 7 | "https://www.googleapis.com/auth/script.external_request", 8 | "https://www.googleapis.com/auth/script.send_mail", 9 | "https://www.googleapis.com/auth/userinfo.email" 10 | 11 | ], 12 | "runtimeVersion": "V8" 13 | } 14 | 15 | -------------------------------------------------------------------------------- /extra_functionality/on_open.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific lan guage governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | const PARTNER_ID = SpreadsheetApp.getActiveSpreadsheet() 18 | .getActiveSheet() 19 | .getRange(2, 2) 20 | .getValue(); 21 | const ADVERTISER_ID = SpreadsheetApp.getActiveSpreadsheet() 22 | .getActiveSheet() 23 | .getRange(3, 2) 24 | .getValue(); 25 | 26 | /** 27 | * Creates a custom menu with an option to send feedback directly in the tool 28 | */ 29 | function onOpen() { 30 | let ui = SpreadsheetApp.getUi(); 31 | ui.createMenu('Script Builder') 32 | .addItem('Send Feedback', 'sendFeedback') 33 | .addItem('Open DV360 (Adv)', 'openAdvDV360') 34 | .addItem('Open DV360 (Partner)', 'openPartnerDV360') 35 | .addToUi(); 36 | if (firstOpen()) { 37 | response = ui.alert( 38 | 'The Google team who built this solution is requesting to have view access to this spreadsheet, to collect usage and error data. This data will allow the team to: \n \n' + 39 | '\0 \0 \0 \0 \0 \0 \0 \0 \0 \u2022 monitor common errors and premptively fix them \n' + 40 | '\0 \0 \0 \0 \0 \0 \0 \0 \0 \u2022 collect aggregate usage data to justify continued support for the solution \n \n' + 41 | 'You will be able to remove this access at any time from the native user sharing menu. Would you like to grant view access to cb-script-builder-tracking@google.com?', 42 | ui.ButtonSet.YES_NO); 43 | if (response == ui.Button.YES) { 44 | try { 45 | const ss = SpreadsheetApp.getActiveSpreadsheet(); 46 | ss.addViewer('cb-script-builder-tracking@google.com'); 47 | ui.alert('Sharing was a success'); 48 | } catch (err) { 49 | ui.alert( 50 | 'There was an error. Please manually add cb-script-builder-tracking@google.com as a viewer.'); 51 | } 52 | } 53 | } 54 | } 55 | 56 | 57 | /** 58 | * Checks if this is first time the spreadsheet has been opened 59 | */ 60 | function firstOpen() { 61 | const ps = PropertiesService.getScriptProperties(); 62 | let loginCheck = ps.getProperty('First Login'); 63 | if (!loginCheck) { 64 | ps.setProperty('First Login', 'YES'); 65 | return true; 66 | } else { 67 | return false; 68 | } 69 | } 70 | 71 | 72 | /** 73 | * Adds ability for users to send a feedback email directly from the UI 74 | */ 75 | function sendFeedback() { 76 | try { 77 | let ui = SpreadsheetApp.getUi(); 78 | response = ui.alert( 79 | 'You can provide feedback on this solution by sending an email to cb-script-builder+feedback@google.com.\n Alternatively, you can provide feedback directly via this dialogue box. Would like to proceed with that option?', 80 | ui.ButtonSet.YES_NO); 81 | if (response == ui.Button.YES) { 82 | let subject = ui.prompt('Please give a short title for your feedback'); 83 | if (subject.getSelectedButton() != ui.Button.OK) { 84 | return; 85 | } 86 | let body = ui.prompt('Please provide your full feedback message below'); 87 | if (body.getSelectedButton() != ui.Button.OK) { 88 | return; 89 | } 90 | MailApp.sendEmail({ 91 | to: 'cb-script-builder+feedback@google.com', 92 | subject: subject.getResponseText(), 93 | body: body.getResponseText() 94 | }); 95 | } 96 | logFunctionRun('Send Feedback'); 97 | } catch (err) { 98 | Browser.msgBox('ERROR', err.message, Browser.Buttons.OK); 99 | logFunctionRun('Send Feedback', err); 100 | } 101 | } 102 | 103 | /** 104 | * Opens DV360 UI to Advertiser's Custom Bidding page 105 | * Wrapper function is necessary because functions called from the menu cannot 106 | * pass parameters 107 | */ 108 | function openAdvDV360() { 109 | try { 110 | openDV360('Advertiser'); 111 | logFunctionRun('Open DV360 Adv'); 112 | } catch (err) { 113 | Browser.msgBox('ERROR', err.message, Browser.Buttons.OK); 114 | logFunctionRun('Open DV360 Adv', err); 115 | } 116 | } 117 | 118 | /** 119 | * Opens DV360 UI to Partner's Custom Bidding page 120 | * Wrapper function is necessary because functions called from the menu cannot 121 | * pass parameters 122 | */ 123 | function openPartnerDV360() { 124 | try { 125 | openDV360('Partner'); 126 | logFunctionRun('Open DV360 Partner'); 127 | } catch (err) { 128 | Browser.msgBox('ERROR', err.message, Browser.Buttons.OK); 129 | logFunctionRun('Open DV360 Partner', err); 130 | } 131 | } 132 | 133 | /** 134 | * Opens DV360 UI to Custom Bidding page in a new tab 135 | * @param {string} hierarchyLevel The hierarchy level (Partner or Advertiser) 136 | * where the platform should open 137 | */ 138 | 139 | function openDV360(hierarchyLevel) { 140 | try { 141 | htmlTemplate = 142 | HtmlService.createTemplateFromFile('CustomBiddingRedirect.html'); 143 | if (hierarchyLevel == 'Advertiser') { 144 | htmlTemplate.redirect_url = 'https://displayvideo.google.com/ng_nav/p/' + 145 | PARTNER_ID + '/a/' + ADVERTISER_ID + '/custom-bidding'; 146 | } else if (hierarchyLevel == 'Partner') { 147 | htmlTemplate.redirect_url = 'https://displayvideo.google.com/ng_nav/p/' + 148 | PARTNER_ID + '/custom-bidding'; 149 | } 150 | let htmlOutput = htmlTemplate.evaluate().getContent(); 151 | SpreadsheetApp.getUi().showModalDialog( 152 | HtmlService.createHtmlOutput(htmlOutput).setHeight(50), 153 | 'Opening DV360'); 154 | } catch (err) { 155 | Browser.msgBox('ERROR', err.message, Browser.Buttons.OK); 156 | logFunctionRun('Open DV360', err); 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /extra_functionality/tracking.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2023 Google LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * Writes data to the tracking sheet based on what function was run and whether 19 | * or not it triggered an error 20 | * @param {string} functionName The name of the function being executed 21 | * @param {string=} error The error message 22 | */ 23 | 24 | function logFunctionRun(functionName, err) { 25 | let ss = SpreadsheetApp.getActiveSpreadsheet(); 26 | let sheet = ss.getSheetByName('Error Tracking'); 27 | let ss_id = SpreadsheetApp.getActiveSpreadsheet().getId(); 28 | let partner_id = PARTNER_ID; 29 | let adv_id = ADVERTISER_ID; 30 | let user = Session.getActiveUser().getEmail(); 31 | let status = ''; 32 | if (err == undefined) { 33 | error = ''; 34 | status = 'Success'; 35 | } else { 36 | error = err.message; 37 | status = err.name; 38 | }; 39 | ss.setSpreadsheetTimeZone(Session.getScriptTimeZone()); 40 | let ts = new Date(); 41 | sheet.appendRow([ts, ss_id, partner_id, adv_id, user, functionName, status, error]); 42 | } 43 | --------------------------------------------------------------------------------