# Google Pub/Sub

<p><a href="https://cloud.google.com/pubsub/docs/overview" >Google Pub/Sub</a> is an asynchronous messaging service that allows you to decouple the services that produce events from the services that process events. With Pub/Sub, you get durable message storage as well as a real-time message delivery system. The Google Pub/Sub servers run reliably with a consistent performance in all Google Cloud regions over the world.</p>
<p>RudderStack allows you to configure Google Pub/Sub as a destination and send your event data to it directly.</p>
<p>Find the open source transformer code for this destination in the <a href="https://github.com/rudderlabs/rudder-transformer/tree/main/src/v0/destinations/googlepubsub" >GitHub repository</a>.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="connection-compatibility">Connection compatibility</h2>
  
  
  
  <div class="quick-info">
    <div>
      <div class="connection-modes-column-headers">
        <table>
          <tr class="connection-modes-column-headers">
            <th colspan="4">
            Destination Information
          </th>
        </tr>
          <tr class="destination-info-content">
            <td>
              <ul>
                <li>
                  <b>Status:</b> Generally Available 
                </li>
                <li>
                  <b>Supported sources:</b>  
                  
                      Android (Java)
                      ,
                  
                  
                      Android (Kotlin)
                      ,
                  
                  
                      iOS (Obj-C)
                      ,
                  
                  
                      iOS (Swift)
                      ,
                  
                  
                      Web,
                  
                  
                      Unity,
                  
                  
                      AMP
                      ,
                  
                  
                      Cloud,
                  
                  
                      Warehouse,
                  
                  
                      React Native
                      ,
                  
                  
                      Flutter,
                  
                  
                      Cordova,
                  
                  
                      Shopify
                  
                </li>
                <li>
                  Refer to it as <b>Google Cloud Pub/Sub</b> in the <a href="/docs/sources/event-streams/sdks/rudderstack-javascript-sdk/filtering/#filtering-destinations">Integrations object</a>.
                </li>
              </ul>
            </td>
          </tr>
        </table>
      </div>
      <div class="table-content connection-modes-table">
        
          <table>
            <tr class="heading connection-modes-header">
              <th colspan="4">
              Connection Modes
              <a href=/docs/destinations/rudderstack-connection-modes>
                <i class="fa-regular fa-circle-info"></i>
              </a>
            </th>
          </tr>
            <tr class="connection-modes-column-headers">
              <th>Source</th>
              <th>Cloud mode</th>
              <th>Device mode</th>
              <th>Hybrid mode</th>
            </tr>
            
            <tr class="connection-modes-row">
              <td>
                AMP
                
              </td>
              <td>
                <img src=/docs/images/tick.svg loading="lazy" decoding="async" class="img__small" alt="supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
            </tr>
            
            <tr class="connection-modes-row">
              <td>
                Android (Java)
                
              </td>
              <td>
                <img src=/docs/images/tick.svg loading="lazy" decoding="async" class="img__small" alt="supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
            </tr>
            
            <tr class="connection-modes-row">
              <td>
                Android (Kotlin)
                
              </td>
              <td>
                <img src=/docs/images/tick.svg loading="lazy" decoding="async" class="img__small" alt="supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
            </tr>
            
            <tr class="connection-modes-row">
              <td>
                Cloud
                
              </td>
              <td>
                <img src=/docs/images/tick.svg loading="lazy" decoding="async" class="img__small" alt="supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
            </tr>
            
            <tr class="connection-modes-row">
              <td>
                Cordova
                
              </td>
              <td>
                <img src=/docs/images/tick.svg loading="lazy" decoding="async" class="img__small" alt="supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
            </tr>
            
            <tr class="connection-modes-row">
              <td>
                Flutter
                
              </td>
              <td>
                <img src=/docs/images/tick.svg loading="lazy" decoding="async" class="img__small" alt="supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
            </tr>
            
            <tr class="connection-modes-row">
              <td>
                iOS (Obj-C)
                
              </td>
              <td>
                <img src=/docs/images/tick.svg loading="lazy" decoding="async" class="img__small" alt="supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
            </tr>
            
            <tr class="connection-modes-row">
              <td>
                iOS (Swift)
                
              </td>
              <td>
                <img src=/docs/images/tick.svg loading="lazy" decoding="async" class="img__small" alt="supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
            </tr>
            
            <tr class="connection-modes-row">
              <td>
                React Native
                
              </td>
              <td>
                <img src=/docs/images/tick.svg loading="lazy" decoding="async" class="img__small" alt="supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
            </tr>
            
            <tr class="connection-modes-row">
              <td>
                Shopify
                
              </td>
              <td>
                <img src=/docs/images/tick.svg loading="lazy" decoding="async" class="img__small" alt="supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
            </tr>
            
            <tr class="connection-modes-row">
              <td>
                Unity
                
              </td>
              <td>
                <img src=/docs/images/tick.svg loading="lazy" decoding="async" class="img__small" alt="supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
            </tr>
            
            <tr class="connection-modes-row">
              <td>
                Warehouse
                
              </td>
              <td>
                <img src=/docs/images/tick.svg loading="lazy" decoding="async" class="img__small" alt="supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
            </tr>
            
            <tr class="connection-modes-row">
              <td>
                Web
                
              </td>
              <td>
                <img src=/docs/images/tick.svg loading="lazy" decoding="async" class="img__small" alt="supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
              <td>
                 <img src=/docs/images/no-image.svg loading="lazy"
                    decoding="async" class="img__small" alt="not supported" />
              </td>
            </tr>
            
          </table>
         
      </div>
      <div class="table-content message-types-table">
          <table>
            <tr class="heading message-types-header">
              <th colspan="9">
              Supported Message Types
            </th>
          </tr>
          <tr class="message-types-column-headers">
            <th>Source</th>
            <th>Identify</th>
            <th>Page</th>
            <th>Track</th>
            <th>Screen</th>
            <th>Group</th>
            <th>Alias</th>
            <th>Record</th>
            <th>AudienceList</th>
          </tr>
          
          
          
          
          
            </table>
        </div>
    </div>
  </div>
  

<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="get-started">Get started</h2><p>Once you have confirmed that the platform supports sending events to Google Pub/Sub, perform the steps below:</p>
<ul>
<li>From your <a href="https://app.rudderlabs.com/" >RudderStack dashboard</a>, add the source. From the list of destinations, select <strong>Google Pub/Sub.</strong></li>
<li>Give a name to the destination and click <strong>Next</strong>. You should then see the following screen:</li>
</ul>
<p>

<figure class="image--main "  >
    <a 
         href="/docs/images/image%20%2879%29%20%282%29%20%282%29%20%283%29%20%283%29%20%283%29%20%282%29%20%282%29.webp"
        
        >
        <img src="/docs/images/image%20%2879%29%20%282%29%20%282%29%20%283%29%20%283%29%20%283%29%20%282%29%20%282%29.webp" 
         
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>

Google Pub/Sub Connection Settings</p>
<ul>
<li>Enter the following details:
<ul>
<li><strong>Connection Settings</strong>
<ul>
<li><strong>Project ID</strong> and the <strong>Credentials</strong>: Follow these steps to obtain the project ID as well as the required credentials:
<ul>
<li>Create a service account from Google Cloud Console.</li>
<li>You can get the <strong>Project ID</strong> when you log in to your Google Cloud Console.</li>
<li>Use the <strong>Select a role</strong> dropdown to add the <strong>Pub/Sub Publisher</strong> role.</li>
<li>Create a key as JSON and download it.</li>
<li>Paste this downloaded JSON in the <strong>Credentials</strong> field</li>
</ul>
</li>
<li>Enter the <strong>Event Name</strong> as well as the corresponding <strong>Topic ID</strong>. You can get the topic id from your topics page:</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>

<figure class="image--main "  >
    <a 
         href="/docs/images/image%20%2848%29.webp"
        
        >
        <img src="/docs/images/image%20%2848%29.webp" 
         
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>

Google Pub/Sub Topic ID and Name</p>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text"><p>You can send an event <code>type</code> like <code>page,</code> <code>identify,</code> <code>track</code>.
For the <code>track</code> events you can specify the event name based on the <code>event</code> name in the payload.</p>
<p>For example:</p>
<ul>
<li>If the event name is <code>page</code> it will send all calls with the <code>type</code> page.</li>
<li>If the event name is <code>product added</code> , it will send all track events with the <code>event</code> as <code>product added</code>.</li>
</ul>
</div>
  </div>
</blockquote>

</html>

<blockquote class="success">
  <div class="tip-quote">
    
    <div class="tip-text">
      If you want to send all events to a particular stream irrespective of the type or name, you can use <code>*</code> as the event name.
    </div>
  </div>
</blockquote>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">The <strong>topic ID</strong> is <strong>case-sensitive</strong> and has to be exactly as seen in Google Pub/Sub. On the other hand, the <strong>event name</strong> is <strong>case insensitive</strong>, and thus <code>Page</code> or <code>page</code> will both be considered as valid.</div>
  </div>
</blockquote>
<ul>
<li>Finally, click <strong>Next</strong> to complete the configuration. Pub/Sub should now be added and enabled as a destination in RudderStack.</li>
</ul>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="attributes">Attributes</h2><p>You can send attributes to Google Pub/Sub along with the message. In order to send the attributes, enter the required attribute mapping in the RudderStack dashboard as seen below:</p>

<figure class="image--main "  >
    <a 
         href="/docs/images/image%20%28113%29.webp"
        
        >
        <img src="/docs/images/image%20%28113%29.webp" 
         
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>

<p>The following are some examples:</p>
<ul>
<li>If the <code>event</code> is <strong><code>Product Viewed</code></strong> and the <code>key</code> is <strong><code>coupon</code></strong>, RudderStack will add the <code>coupon</code> key-value pair from the message to the attributes&rsquo; metadata object.</li>
<li>If multiple mappings are provided for <strong><code>Product Viewed</code></strong>, all such key-value pairs from the message body will be added to attributes&rsquo; metadata object.</li>
<li>If the event name is <strong><code>page</code></strong> it will send all calls with the <code>type</code> page.</li>
</ul>

<blockquote class="warning">
  <div class="tip-quote">
    
    <div class="tip-text">For the <code>key</code> fields provided in the attributes map, the <code>key</code> is searched in the message body in <code>root</code>, <code>properties</code>, <code>traits</code> and <code>context.traits</code> - in that specific order.</div>
  </div>
</blockquote>
<p><strong>Note: You can also specify the key path in the payload using the dot notation.</strong></p>
<p>For example:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.track(&#34;Track me&#34;, {
  category: &#34;category&#34;,
  label: &#34;label&#34;,
  value: &#34;value&#34;,
  metadata: {
    metadataId: &#34;sample-id&#34;
  }
});</code></pre></div>
</div>
<p>For the above <code>track</code> call, you can specify an attribute mapping for <code>metadataID</code> as shown below:</p>
<table>
  <thead>
      <tr>
          <th><strong>Event</strong></th>
          <th><strong>Field</strong></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Track me</td>
          <td><code>metadata.metadataId</code></td>
      </tr>
  </tbody>
</table>
<p>This will create the below attribute metadata object:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">{
   metadataId: &#34;sample-id&#34;
}</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="page">Page</h2><p>The <code>page</code> call contains information related to the page, such as the URL of the web page visited by the user.</p>
<p>A sample <code>page</code> payload is as shown in the snippet below:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.page({
  path: &#34;path&#34;,
  url: &#34;url&#34;,
  title: &#34;title&#34;,
  search: &#34;search&#34;,
  referrer: &#34;referrer&#34;,
})</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="identify">Identify</h2><p>The <code>identify</code> call captures the relevant details about the visiting user.</p>
<p>A sample <code>identify</code> payload is as shown in the snippet below:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.identify(&#34;abc123&#34;, {
  name: &#34;FirstName LastName&#34;,
  email: &#34;example@gmail.com&#34;,
})</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="track">Track</h2><p>The <code>track</code> call captures the information related to the actions performed by the user, along with their properties, or traits.</p>
<p>A sample <code>track</code> payload is as shown in the snippet below:</p>
<div class="rs-code">
  <div class="rs-code__head">javascript<button class="rs-code__copy" type="button">
      
      Copy
    </button>
  </div>
  <div class="highlight"><pre class="chroma"><code class="language-javascript" data-lang="javascript">rudderanalytics.track(&#34;Track me&#34;, {
  category: &#34;category&#34;,
  label: &#34;label&#34;,
  value: &#34;value&#34;,
})</code></pre></div>
</div>
<!-- end-chunk -->
<!-- begin-chunk -->
<h2 id="faq">FAQ</h2><!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="how-does-event-mapping-work-with-the-topic-id">How does event mapping work with the topic ID?</h4><ul>
<li>If there is no topic ID set for an event, it will not be sent.</li>
<li>If an event is set with a topic id, the payload will be sent to Pub/Sub to that particular topic id.</li>
</ul>

<html lang="en">
<blockquote class="info">
  <div class="tip-quote">
    
    <div class="tip-text">If you have set all event type, event and <code>*</code> for mapping the priority will be given to <code>event</code> ,
then <code>type</code> , followed by <code>*</code>.</div>
  </div>
</blockquote>

</html>
<p>For example, let the type of event be <code>track</code>, the event name be <code>product added</code>. The mapping is done as:</p>

<figure class="image--main "  >
    <a 
         href="/docs/images/screenshot-2020-09-09-at-6.56.02-pm.webp"
        
        >
        <img src="/docs/images/screenshot-2020-09-09-at-6.56.02-pm.webp" 
         
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>

<p>Now all events should go to the topic mapped with <strong><code>product added</code></strong>.</p>
<!-- end-chunk -->
<!-- begin-chunk -->
<h4 id="how-do-i-provide-multiple-attribute-mapping-for-a-particular-event">How do I provide multiple Attribute mapping for a particular event?</h4><p>In order to send multiple attribute keys for a particular event, enter the required mappings in the RudderStack dashboard as seen below:</p>

<figure class="image--main "  >
    <a 
         href="/docs/images/image%20%28112%29.webp"
        
        >
        <img src="/docs/images/image%20%28112%29.webp" 
         
         
         
        decoding="async" loading="lazy" class="img-shortcode"/>
    </a>
    
</figure>


