|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "metadata": { |
| 6 | + "ein.tags": "worksheet-0", |
| 7 | + "slideshow": { |
| 8 | + "slide_type": "-" |
| 9 | + } |
| 10 | + }, |
| 11 | + "source": [ |
| 12 | + "## Generate ads for search engine marketing campaigns\n", |
| 13 | + "\n", |
| 14 | + "Utilizing Python, this is a recipe that shows how to generate differnent ad templates for our campaigns and ad groups.\n", |
| 15 | + "\n", |
| 16 | + "This is not specific to Python and the recipe can be implemented in any other language." |
| 17 | + ] |
| 18 | + }, |
| 19 | + { |
| 20 | + "cell_type": "code", |
| 21 | + "execution_count": 2, |
| 22 | + "metadata": { |
| 23 | + "autoscroll": false, |
| 24 | + "collapsed": false, |
| 25 | + "ein.tags": "worksheet-0", |
| 26 | + "slideshow": { |
| 27 | + "slide_type": "-" |
| 28 | + } |
| 29 | + }, |
| 30 | + "outputs": [], |
| 31 | + "source": [ |
| 32 | + "import csv # the main package simply to save the ads table to a file" |
| 33 | + ] |
| 34 | + }, |
| 35 | + { |
| 36 | + "cell_type": "markdown", |
| 37 | + "metadata": { |
| 38 | + "ein.tags": "worksheet-0", |
| 39 | + "slideshow": { |
| 40 | + "slide_type": "-" |
| 41 | + } |
| 42 | + }, |
| 43 | + "source": [ |
| 44 | + "### Start by first getting a list of all the possible landing pages that are fit to be used in our campaigns.\n", |
| 45 | + "\n", |
| 46 | + "We should also have the title of the landing page (product name) as well. Ideally, we should have them in a list of tuples like this:" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "code", |
| 51 | + "execution_count": 3, |
| 52 | + "metadata": { |
| 53 | + "autoscroll": false, |
| 54 | + "collapsed": false, |
| 55 | + "ein.tags": "worksheet-0", |
| 56 | + "slideshow": { |
| 57 | + "slide_type": "-" |
| 58 | + } |
| 59 | + }, |
| 60 | + "outputs": [], |
| 61 | + "source": [ |
| 62 | + "pages_products = [\n", |
| 63 | + "('http://example.com/?make=toyota&model=camry', 'toyota camry'),\n", |
| 64 | + "('http://example.com/?make=toyota&model=corolla','toyota corolla'),\n", |
| 65 | + "('http://example.com/?make=toyota&model=','toyota'),\n", |
| 66 | + "('http://example.com/?make=honda&model=civic','honda civic'),\n", |
| 67 | + "('http://example.com/?make=honda&model=','honda'),\n", |
| 68 | + " ]" |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + "cell_type": "markdown", |
| 73 | + "metadata": { |
| 74 | + "ein.tags": "worksheet-0", |
| 75 | + "slideshow": { |
| 76 | + "slide_type": "-" |
| 77 | + } |
| 78 | + }, |
| 79 | + "source": [ |
| 80 | + "Another crucial thing to ensure, is having the product names match exactly with the ad groups you create(d) for the keywords, because these will Eventually end up in the same campaigns together and they need to match." |
| 81 | + ] |
| 82 | + }, |
| 83 | + { |
| 84 | + "cell_type": "markdown", |
| 85 | + "metadata": { |
| 86 | + "ein.tags": "worksheet-0", |
| 87 | + "slideshow": { |
| 88 | + "slide_type": "-" |
| 89 | + } |
| 90 | + }, |
| 91 | + "source": [ |
| 92 | + "Eventually, we want to end up with a table like this:\n", |
| 93 | + "\n", |
| 94 | + "| Campaign | Ad Group | Headline 1 | Headline 2 | Description | Display URL | Final URL |\n", |
| 95 | + "|----------|----------------|----------------------------|--------------------------|-----------------------------------------------------|-------------|------------------------------------------------|\n", |
| 96 | + "| SEM Cars | Toyota | Toyota for Sale | Great Prices and Options | Browse Over 100,000 cars. Book Your Free Test Drive | example.com | http://example.com/?make=toyota&model=' |\n", |
| 97 | + "| SEM Cars | Toyota | Second Hand Toyota | Great Prices and Options | Browse Over 100,000 cars. Book Your Free Test Drive | example.com | http://example.com/?make=toyota&model=' |\n", |
| 98 | + "| SEM Cars | Toyota Corolla | Toyota Corolla for Sale | Great Prices and Options | Browse Over 100,000 cars. Book Your Free Test Drive | example.com | http://example.com/?make=toyota&model=corolla' |\n", |
| 99 | + "| SEM Cars | Toyota Corolla | Second Hand Toyota Corolla | Great Prices and Options | Browse Over 100,000 cars. Book Your Free Test Drive | example.com | http://example.com/?make=toyota&model=corolla' |\n", |
| 100 | + "| SEM Cars | Honda | Honda for Sale | Great Prices and Options | Browse Over 100,000 cars. Book Your Free Test Drive | example.com | http://example.com/?make=honda&model=' |\n", |
| 101 | + "| SEM Cars | Honda | Second Hand Honda | Great Prices and Options | Browse Over 100,000 cars. Book Your Free Test Drive | example.com | http://example.com/?make=honda&model=' |\n", |
| 102 | + "\n", |
| 103 | + "\n" |
| 104 | + ] |
| 105 | + }, |
| 106 | + { |
| 107 | + "cell_type": "code", |
| 108 | + "execution_count": 6, |
| 109 | + "metadata": { |
| 110 | + "autoscroll": false, |
| 111 | + "collapsed": false, |
| 112 | + "ein.tags": "worksheet-0", |
| 113 | + "slideshow": { |
| 114 | + "slide_type": "-" |
| 115 | + } |
| 116 | + }, |
| 117 | + "outputs": [ |
| 118 | + { |
| 119 | + "name": "stdout", |
| 120 | + "output_type": "stream", |
| 121 | + "text": [ |
| 122 | + "['Campaign', 'Ad Group', 'Headline 1', 'Headline 2', 'Description', 'Final URL']\n", |
| 123 | + "['SEM Cars', 'toyota camry', 'toyota camry for Sale', 'Great Prices and Options', 'Browse Over 100,000 Cars. Book Your Free Test Drive', 'http://example.com/?make=toyota&model=camry']\n", |
| 124 | + "['SEM Cars', 'toyota camry', 'Second Hand toyota camry', 'Great Prices and Options', 'Browse Over 100,000 Cars. Book Your Free Test Drive', 'http://example.com/?make=toyota&model=camry']\n", |
| 125 | + "['SEM Cars', 'toyota corolla', 'toyota corolla for Sale', 'Great Prices and Options', 'Browse Over 100,000 Cars. Book Your Free Test Drive', 'http://example.com/?make=toyota&model=corolla']\n", |
| 126 | + "['SEM Cars', 'toyota corolla', 'Second Hand toyota corolla', 'Great Prices and Options', 'Browse Over 100,000 Cars. Book Your Free Test Drive', 'http://example.com/?make=toyota&model=corolla']\n", |
| 127 | + "['SEM Cars', 'toyota', 'toyota for Sale', 'Great Prices and Options', 'Browse Over 100,000 Cars. Book Your Free Test Drive', 'http://example.com/?make=toyota&model=']\n", |
| 128 | + "['SEM Cars', 'toyota', 'Second Hand toyota', 'Great Prices and Options', 'Browse Over 100,000 Cars. Book Your Free Test Drive', 'http://example.com/?make=toyota&model=']\n", |
| 129 | + "['SEM Cars', 'honda civic', 'honda civic for Sale', 'Great Prices and Options', 'Browse Over 100,000 Cars. Book Your Free Test Drive', 'http://example.com/?make=honda&model=civic']\n", |
| 130 | + "['SEM Cars', 'honda civic', 'Second Hand honda civic', 'Great Prices and Options', 'Browse Over 100,000 Cars. Book Your Free Test Drive', 'http://example.com/?make=honda&model=civic']\n", |
| 131 | + "['SEM Cars', 'honda', 'honda for Sale', 'Great Prices and Options', 'Browse Over 100,000 Cars. Book Your Free Test Drive', 'http://example.com/?make=honda&model=']\n", |
| 132 | + "['SEM Cars', 'honda', 'Second Hand honda', 'Great Prices and Options', 'Browse Over 100,000 Cars. Book Your Free Test Drive', 'http://example.com/?make=honda&model=']\n" |
| 133 | + ] |
| 134 | + } |
| 135 | + ], |
| 136 | + "source": [ |
| 137 | + "ads_list = [['Campaign', 'Ad Group', 'Headline 1', 'Headline 2', 'Description', 'Final URL']]\n", |
| 138 | + "\n", |
| 139 | + "for page, adgroup in pages_products:\n", |
| 140 | + " row = [\n", |
| 141 | + " 'SEM Cars',\n", |
| 142 | + " adgroup,\n", |
| 143 | + " f'{adgroup} for Sale',\n", |
| 144 | + " 'Great Prices and Options',\n", |
| 145 | + " 'Browse Over 100,000 Cars. Book Your Free Test Drive',\n", |
| 146 | + " page\n", |
| 147 | + " ]\n", |
| 148 | + " ads_list.append(row)\n", |
| 149 | + "\n", |
| 150 | + " row = [\n", |
| 151 | + " 'SEM Cars',\n", |
| 152 | + " adgroup,\n", |
| 153 | + " f'Second Hand {adgroup}',\n", |
| 154 | + " 'Great Prices and Options',\n", |
| 155 | + " 'Browse Over 100,000 Cars. Book Your Free Test Drive',\n", |
| 156 | + " page\n", |
| 157 | + " ]\n", |
| 158 | + " ads_list.append(row)\n", |
| 159 | + "\n", |
| 160 | + "print(*ads_list, sep='\\n')" |
| 161 | + ] |
| 162 | + }, |
| 163 | + { |
| 164 | + "cell_type": "markdown", |
| 165 | + "metadata": { |
| 166 | + "ein.tags": "worksheet-0", |
| 167 | + "slideshow": { |
| 168 | + "slide_type": "-" |
| 169 | + } |
| 170 | + }, |
| 171 | + "source": [ |
| 172 | + "And we are done!\n", |
| 173 | + "\n", |
| 174 | + "Some things to keep in mind:\n", |
| 175 | + "\n", |
| 176 | + "- The ad text needs to be carefully written and reflect the business's strategy, branding, etc.\n", |
| 177 | + "- An issue you will definitely face is the character limit restriction. The solution will depend on the average length of your product names. Accordingly you can put the names in the correct field (headline or Description), or you might find a special solution for long and short names.\n", |
| 178 | + "- I'm using Python's f-strings to dynamically insert the proper word. You can use older % formatting, or string formatting, and it's also very easy to implement in other languages. It's simple text concatenation.\n", |
| 179 | + "- There are several different places where you can insert the product name, and this should also be thought of, and you can be creative. \n", |
| 180 | + "\n", |
| 181 | + "Now we save the ads in a csv file:\n" |
| 182 | + ] |
| 183 | + }, |
| 184 | + { |
| 185 | + "cell_type": "code", |
| 186 | + "execution_count": 7, |
| 187 | + "metadata": { |
| 188 | + "autoscroll": false, |
| 189 | + "collapsed": false, |
| 190 | + "ein.tags": "worksheet-0", |
| 191 | + "slideshow": { |
| 192 | + "slide_type": "-" |
| 193 | + } |
| 194 | + }, |
| 195 | + "outputs": [], |
| 196 | + "source": [ |
| 197 | + "with open('ads.csv', 'wt', newline='') as f:\n", |
| 198 | + " writer = csv.writer(f)\n", |
| 199 | + " for line in ads_list:\n", |
| 200 | + " writer.writerow(line)" |
| 201 | + ] |
| 202 | + } |
| 203 | + ], |
| 204 | + "metadata": { |
| 205 | + "kernelspec": { |
| 206 | + "display_name": "Python 3", |
| 207 | + "name": "python3" |
| 208 | + }, |
| 209 | + "name": "sem_generate_ads.ipynb" |
| 210 | + }, |
| 211 | + "nbformat": 4, |
| 212 | + "nbformat_minor": 2 |
| 213 | +} |
0 commit comments