<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yu Tsuno on Medium]]></title>
        <description><![CDATA[Stories by Yu Tsuno on Medium]]></description>
        <link>https://medium.com/@tsunochi17?source=rss-ad42b6b0a173------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*jvCfgrLa7AIL-966</url>
            <title>Stories by Yu Tsuno on Medium</title>
            <link>https://medium.com/@tsunochi17?source=rss-ad42b6b0a173------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 17:39:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tsunochi17/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Automate Adding Google Trends Keyword to Google Ads Search Campaigns]]></title>
            <link>https://medium.com/@tsunochi17/automate-adding-google-trends-keyword-to-google-ads-search-campaigns-e6808364ca4?source=rss-ad42b6b0a173------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6808364ca4</guid>
            <category><![CDATA[google-trends]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[google-ads]]></category>
            <category><![CDATA[google-ads-scripts]]></category>
            <dc:creator><![CDATA[Yu Tsuno]]></dc:creator>
            <pubDate>Sun, 14 Jun 2020 19:15:18 GMT</pubDate>
            <atom:updated>2021-10-03T21:53:52.634Z</atom:updated>
            <content:encoded><![CDATA[<h4>Update your Search Campaign with the Newest Trend</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kinMmt-pNcRhABXgoVtmBA.png" /><figcaption>Solution Structure Overview</figcaption></figure><h3>Why Using this Solution? Google Trends Data For Google Ads Search Campaigns?</h3><p>Advertisers who use SEM tools like <a href="https://ads.google.com/home/">Google Ads</a>, often use <a href="https://trends.google.com/trends/">Google Trends</a> to check the user searching behaviour change in the market based on organic searches. This solution was created to automate the process of adding relevant Google Trends Rising and Top related queries into Google Ads Search Campaigns. It would help reduce some manual daily work and errors who is working or monitoring Search Campaigns and Google Trends keywords. Main code is written in Python 3.7.</p><p><a href="https://github.com/tsunoyu/pytrends_googleads">Github Link</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zBtMmM5SIHF1IS0axW9AzA.png" /><figcaption>Google Trends Data (Rising and Top Related Queries)</figcaption></figure><h3>Important Notes Before Starting The Actual Implementation</h3><ul><li>This solution will NOT guarantee any Search Ads performance improvement</li><li><a href="https://pypi.org/project/pytrends/">pytrends API</a> is not a Google Official API but it can be used for free</li><li>Running the Python code daily basis will incur some Google Cloud cost</li><li>It will not work if the query does not have any organic search volume to capture the search trend.</li><li>Try to adjust the filter in case the search volume is low. ex) target from one country to Global</li><li>Consider adding filter or alert in Google Ads side to avoid sudden ads spend increase</li></ul><h3>Products and APIs Used For This Solution</h3><ul><li><a href="https://pypi.org/project/pytrends/">pytrends</a> (API to get Google Trends data. Again this is not an official API by Google)</li><li><a href="https://cloud.google.com/functions/docs">Google Cloud Function</a> (Main code sits here)</li><li><a href="https://cloud.google.com/pubsub/docs/">Google Cloud Pub/Sub</a> (This will trigger the Cloud Function)</li><li><a href="https://cloud.google.com/scheduler/docs/quickstart">Google Cloud Scheduler</a> (Schedule the trigger)</li><li><a href="https://developers.google.com/sheets/api">Google Sheets API</a> (Spreadsheet will be used to store the Google Trend Keyword data)</li><li><a href="https://developers.google.com/google-ads/scripts/docs/your-first-script">Google Ads Script</a> (Update Campaign Keyword referencing the data from Spreadsheet)</li></ul><h3>Implementation Guide</h3><p>The general implementation guide and sample codes are already published in <a href="https://github.com/tsunoyu/pytrends_googleads">Github</a>. However in the following sections I wrote some additional details including my learning process till deploying this code in Google Cloud.</p><h4>Step 1. Discover the pytrends API</h4><p>What is pytrends?</p><blockquote>Unofficial API for Google Trends. Allows simple interface for automating downloading of reports from Google Trends. Only good until Google changes their backend again :-P.</blockquote><p><a href="https://pypi.org/project/pytrends/">pytrends</a></p><p>You can install it with “pip ” command.</p><pre>pip install pytrends</pre><p>Once you are done with installation, import them in your Python code and set some required parameters.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd0406f6f9821609ccb4416629f67e36/href">https://medium.com/media/fd0406f6f9821609ccb4416629f67e36/href</a></iframe><p>For example above code is requesting the last 7 days related queries for “Playstation” in US. The last print function returns below double dimensional dictionary format 25 each related queries for Rising and Top Trending ones.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/da16e71ae71d4eaeaeecd8b26449066e/href">https://medium.com/media/da16e71ae71d4eaeaeecd8b26449066e/href</a></iframe><p>The number values showing in the data is the scoring calculated by Google on a relative scale. Below section is the detail explanation about Rising and Top queries.</p><blockquote><strong>Related queries</strong></blockquote><blockquote>Users searching for your term also searched for these queries. You can sort by the following metrics:</blockquote><blockquote>* <strong>Top</strong> — The most popular search queries. Scoring is on a relative scale where a value of 100 is the most commonly searched query, 50 is a query searched half as often as the most popular query, and so on.</blockquote><blockquote>* <strong>Rising</strong> — Queries with the biggest increase in search frequency since the last time period. Results marked “Breakout” had a tremendous increase, probably because these queries are new and had few (if any) prior searches.</blockquote><p>Now cleaning the data a little bit with Pandas dividing into two dataframes Rising and Top queries.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e3e30e14d1c901161a0c044d6ad3642/href">https://medium.com/media/2e3e30e14d1c901161a0c044d6ad3642/href</a></iframe><p>Checking the new created dataframe using “head()”.</p><pre># Show head of Rising Query Pandas Dataframe<br>rising_q.haed()</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fb6d219725bd09ddae75dc923d1855c4/href">https://medium.com/media/fb6d219725bd09ddae75dc923d1855c4/href</a></iframe><p>In many case, Search Campaigns are separated into two buckets “Brand Term Campaigns” and “Generic Term Campaigns”. In this sample case I defined the keywords including “Playstation” as “Brand Term” and the rest as “Generic”. I know this can be still improved divided into more multiple granular buckets but here we are leaving it simple. This Brand / Generic split is coded below using some Regular Expressions. By customising the Regular Expressions part you can filter the queries more flexibly.</p><p>The last half of the code is the process of creating following four lists.</p><ul><li>Rising Brand Keywords List</li><li>Rising Generic Keywords List</li><li>Top Brand Keywords List</li><li>Top Generic Keywords List</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/de716b96127b84956dc9cbaebf0c5c95/href">https://medium.com/media/de716b96127b84956dc9cbaebf0c5c95/href</a></iframe><pre>print(rising_nonbrand_kw_list)</pre><p>This will print below query list which includes the term “Playstation” in each of the queries.</p><pre>[&#39;playstation 5 digital edition&#39;, <br> &#39;playstation 5 miles morales edition&#39;, <br> &#39;playstation 5 spider man&#39;, <br> &#39;playstation 5 price in usa&#39;, <br> &#39;playstation 5 spiderman edition&#39;, <br> &#39;playstation 5 meme&#39;, <br> &#39;playstation 5 memes&#39;, <br> &#39;playstation 5 price&#39;, <br> &#39;playstation 5 preorder&#39;, <br> &#39;playstation 5 event time&#39;, <br> &#39;playstation 5 specs&#39;]</pre><p>In the next section we will try to push this query list into Google Spreadsheet.</p><h4>Step 2. Create Spreadsheet and Insert Google Trends Data</h4><p>The goal of this section is to input the Google Trends keyword into Spreashsheet second row like below image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cz4FWaDtvQNmqBjUXp_fCQ.png" /></figure><p>Create New Spreadsheet (or copy <a href="https://docs.google.com/spreadsheets/d/1JNCdYSTR_fenS6AB0_RJAZ50nmt96tTPG1WMVgOkBx4/edit#gid=0">this sample Spreadsheet</a>) to store trending keywords you get from Google Trends. The Spreadsheet needs following four tabs.</p><ul><li>rising_brand</li><li>rising_nonbrand</li><li>top_brand</li><li>top_nonbrand</li></ul><p>Enable the Google Sheets API from below link in order to save data you get from pytrends.</p><p><a href="https://developers.google.com/sheets/api/quickstart/python">Python quickstart | Google Sheets | Google for Developers</a></p><p>Save the file credentials.json to your working directory.</p><p><a href="https://github.com/tsunoyu/pytrends_googleads/blob/master/CREDENTIALS.JSON">Sample Credencial JSON file</a></p><p>Once you have the credential file in your working directory you can access the Spreadsheet using the Spreadsheet key which is shows in the Spreadsheet URL.</p><p>example) Spreadsheet key for <a href="https://docs.google.com/spreadsheets/d/1JNCdYSTR_fenS6AB0_RJAZ50nmt96tTPG1WMVgOkBx4/edit#gid=0"><em>https://docs.google.com/spreadsheets/d/</em><strong><em>1JNCdYSTR_fenS6AB0_RJAZ50nmt96tTPG1WMVgOkBx4</em></strong><em>/edit#gid=0</em></a></p><p>is “<strong>1JNCdYSTR_fenS6AB0_RJAZ50nmt96tTPG1WMVgOkBx4</strong>” after d/ till /edit.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/48b0a43fe293915e6a659a73fc8d805c/href">https://medium.com/media/48b0a43fe293915e6a659a73fc8d805c/href</a></iframe><p>In order to insert the date, add additional code to put the date also into the list like following below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c980d9609d72d19cc1a7555e636f224/href">https://medium.com/media/8c980d9609d72d19cc1a7555e636f224/href</a></iframe><p>Now you can insert the keyword list by running below code. It will insert the data into the second row as you can see that the “insert_row” specifies “2” at the end. After running this code you should see the data in the spreadsheet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b504ed89fc60ca807fb57ed8aa4d341a/href">https://medium.com/media/b504ed89fc60ca807fb57ed8aa4d341a/href</a></iframe><h4>Step 3. Setup Google Cloud Pub/Sub to prepare for Function Trigger</h4><p>Before we create the main function in Google Cloud Function, Google Cloud Pub/Sub Topic needs to be created.</p><blockquote><strong>Google Cloud Pub</strong>/<strong>Sub</strong> is a fully-managed, scalable, global and secure messaging service that allows you to send and receive messages among applications and services.</blockquote><p><a href="https://cloud.google.com/pubsub/docs/">Pub/Sub documentation | Cloud Pub/Sub Documentation | Google Cloud</a></p><p>So Cloud Pub/Sub Topic is system where you can send messages and receive messages.</p><p>Create Google Cloud Pub/Sub Topic so that Google Cloud Function can be triggered based on it. The Topic will receive message from Google Cloud Scheduler which we will set up in the later section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LGQpCXn4wA0WuQwQkhalGw.png" /></figure><h4>Step 4. Setup Google Cloud Cloud Scheduler for Repeating the Function Run</h4><p>In order to send a message repeatedly like daily or weekly basis to Cloud Pub/Sub Topic, Cloud Scheduler is one of the best option to do it. In this solution we put the pytrends parameters such as keywords, timezone, languages into the Cloud Scheduler Payload section where you can set the message you send to Cloud Pub/Sub Topic.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8ovCa1m4on_GXRPTbRITHw.png" /></figure><ul><li>Create a new Google Cloud Scheduler job</li><li>Set the frequency in unix-cron format. Weekly or Daily might be already enough.</li><li>Select your timezone</li><li>Target Pub/Sub → Input the Cloud Pub/Sub Topic name you have created</li><li>Set Payload with following parameters in JSON format</li><li>For more detail please follow the <a href="https://pypi.org/project/pytrends/">pytrends API parameters</a></li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ead5ff37422ad960b8f599227df5943/href">https://medium.com/media/2ead5ff37422ad960b8f599227df5943/href</a></iframe><h4>Step 5. Setup Google Cloud Cloud Scheduler for Repeating the Function Run</h4><p>This is the final step to deploy the function in Google Cloud Platform. Before we connect Cloud Function with Pub/Sub and Scheduler we need to adjust the code a little bit discovered in the <strong>Step 1</strong>. and <strong>Step 2</strong>.</p><p>The main function will be triggered once Cloud Pub/Sub Topic receives a message from Cloud Scheduler.</p><p>If it is your first time to touch Cloud Function with Cloud Pub/Sub Trigger, I strongly recommend to go through below Google official tutorial.</p><p><a href="https://cloud.google.com/functions/docs/calling/pubsub">Google Cloud Pub/Sub Triggers | Cloud Functions Documentation</a></p><p>Through this tutorial I understood that Pub/Sub Topic receives the message from Cloud Scheduler which will be passed to Cloud Function with a variable “event” in dictionary format. Somehow this is been passed with base64 unicode and needs to be encoded to UTF-8 in the Cloud Function.</p><pre>pubsub_message = base64.b64decode(event[&#39;data&#39;]).decode(&#39;utf-8&#39;)</pre><p>Because we send the message in JSON format from Cloud Scheduler, json.load is used to use it in our Python function.</p><pre>json_message = json.loads(pubsub_message)</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8eeec555eba2e3c5ec549b74f733602c/href">https://medium.com/media/8eeec555eba2e3c5ec549b74f733602c/href</a></iframe><p>To minimise error I added also some default parameter in the function in case when the message does not include any location, language informations.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e6c5a1a5fbcd16a2e22ca52a823fbc09/href">https://medium.com/media/e6c5a1a5fbcd16a2e22ca52a823fbc09/href</a></iframe><p>Now the code needs to be wrapped into one function. Below is the final sample code in my Github.</p><p><a href="https://github.com/tsunoyu/pytrends_googleads/blob/master/trends_cloud_function.py">tsunoyu/pytrends_googleads</a></p><p>So let’s move on to the actual Cloud Function creation.</p><ul><li>Create a new Google Cloud Function</li><li>Set the Trigger with Cloud Pub/Sub with the Topic you have created</li><li>Select coding language Python 3.7</li><li>For Source Code select the Zip Upload option and uploads the following three files zipped together.</li><li><a href="https://github.com/tsunoyu/pytrends_googleads/blob/master/trends_cloud_function.py">main.py</a>, <a href="https://github.com/tsunoyu/pytrends_googleads/blob/master/requirements.txt">requirements.txt</a>, <a href="https://github.com/tsunoyu/pytrends_googleads/blob/master/credentials.json">credencials.json</a></li></ul><p>The Zip upload option was needed because I could not find a different way to put together the credencials.json information into one code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7ldcTt4JaiAxA_2R1DrEjQ.png" /></figure><p>Once the Cloud Function has been deployed try to run few test using the Cloud Scheduler. If no error shows up in the Cloud Logger UI and if the Spreadsheet has been updated this should be a success.</p><h4>Step 6. Final Step to Reflect the Spreadsheet Data into Google Ads Campaigns with Google Ads Script</h4><p>Google Ads can be controlled by Google Ads Script which is based on JavaScript and it is more handy to use compared to Google Ads API because you don’t need to register anything to use it if you already have Google Ad account.</p><p><a href="https://developers.google.com/google-ads/scripts">Google Ads scripts | Google Developers</a></p><p>Search Campaigns and AdGroup has to be created in advance in Google Ads UI separately. The sample code will update each four Spreadsheet sheets keywords into separate AdGroup following the Spreadsheet structure covered in <strong>Step 2</strong>.</p><ul><li>Create Campaign in Google Ads UI</li><li>Create 4 Ad Group in Google Ads UI for “rising_brand”, “rising_nonbrand”, “top_brand” and “top_nonbrand”</li><li>Create Google Ads Script</li><li>Schedule the Script daily or weekly basis depending on the function trigger frequency.</li></ul><p>The Google Ads Script will start with the part of opening the Spreadsheet and getting the Trend keywords in an array which loops for each four sheets.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/18df5173a12b312b39719b390223f382/href">https://medium.com/media/18df5173a12b312b39719b390223f382/href</a></iframe><p>The keyword with multi words will create the Phrase Match and Exact Match keywords. On the other hand single Keyword will only produce Exact Match in order to avoid further keyword expansion. But of course this can be changed flexibly depending on your Campaign structure and preferences.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7167cdacbda74130251a0e3369c878b3/href">https://medium.com/media/7167cdacbda74130251a0e3369c878b3/href</a></iframe><p>That’s all it for this project.</p><h3>Next Step and Further Improvement</h3><p>I know this is not a perfect solution since Search Campaign structure and SEM strategy is complex. To improve this solution this needs additional Machine Learning running in behind to filter the best performing keyword or to pick the most relevant AdGroup. May be combining Google Cloud Natural Language API could be one option. What do you think?</p><p>Thank you for reading till the end:)<br>Happy coding:)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6808364ca4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>