> ## Documentation Index
> Fetch the complete documentation index at: https://documentation.onesignal.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Event Streams ile Google Sheets entegrasyonu

> Bu kılavuz, OneSignal tarafından oluşturulan mesaj olaylarını analiz etmek için OneSignal'in Event Webhook'ları ile özel bir Google Sheets belgesi arasında bağlantı kurmak için gereken adımları gösterir.

## Event streams'i etkinleştirin

OneSignal uygulamanız için ücretli bir plana ek bir özellik olan [Event streams](./event-streams)'i etkinleştirin. Bu özelliğe erişiminiz yoksa, daha fazla bilgi için Başarı Yöneticiniz veya Hesap Yöneticiniz ile iletişime geçmekten çekinmeyin.

## Apps script dağıtımı oluşturun

OneSignal mesaj olaylarını eklemek istediğiniz Google Sheet'te **Extensions > Apps Script**'e gidin. Ardından, kod düzenleyicisinde mevcut kodu aşağıdakilerle değiştirin:

<Frame>
  <img src="https://mintcdn.com/onesignal/jBdBk5XvQR5eKOks/images/docs/7c26b5c-image5.png?fit=max&auto=format&n=jBdBk5XvQR5eKOks&q=85&s=cd1cd9169236a23d8b06148e2e7943c6" width="898" height="315" data-path="images/docs/7c26b5c-image5.png" />
</Frame>

<CodeGroup>
  ```javascript javascript theme={null}
  function doPost(e) {
      // Log the full request for debugging purposes
    Logger.log("Request received: " + JSON.stringify(e));

    const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
    let jsonData;

    try {
      // Log the postData.contents before parsing
      Logger.log("Post Data Contents: " + e.postData.contents);

      // Attempt to parse the JSON data
      jsonData = JSON.parse(e.postData.contents);
    } catch (error) {
      // Log the error and return an error response
      Logger.log("Failed to parse JSON: " + error);
      return ContentService.createTextOutput(
        JSON.stringify({ status: "error", message: "Invalid JSON" }),
      ).setMimeType(ContentService.MimeType.JSON);
    }

    // Check if the sheet is empty and set headers if necessary
    if (sheet.getLastRow() === 0) {
      sheet.appendRow([
        "User ID",
        "Event ID",
        "Event",
        "Message ID",
        "Message Name",
        "Message Title",
        "Message Contents",
        "Template ID",
        "Subscription ID",
        "Subscription Device Type",
        "Source",
        "Original Timestamp",
      ]);
    }

    // Prepare the row data from the JSON object
    const row = [
      jsonData.user_id || "",
      jsonData.event_id || "",
      jsonData.event || "",
      jsonData.properties ? jsonData.properties.message_id || "" : "",
      jsonData.properties ? jsonData.properties.message_name || "" : "",
      jsonData.properties ? jsonData.properties.message_title || "" : "",
      jsonData.properties ? jsonData.properties.message_contents || "" : "",
      jsonData.properties ? jsonData.properties.template_id || "" : "",
      jsonData.properties ? jsonData.properties.subscription_id || "" : "",
      jsonData.properties
        ? jsonData.properties.subscription_device_type || ""
        : "",
      jsonData.properties ? jsonData.properties.source || "" : "",
      jsonData.originalTimestamp || "",
    ];

    try {
      // Append the new row to the sheet
      sheet.appendRow(row);
    } catch (error) {
      // Log the error if appending the row fails
      Logger.log("Failed to append row: " + error);
      return ContentService.createTextOutput(
        JSON.stringify({ status: "error", message: "Failed to append row" }),
      ).setMimeType(ContentService.MimeType.JSON);
    }

    // Return a success response
    return ContentService.createTextOutput(
      JSON.stringify({ status: "success" }),
    ).setMimeType(ContentService.MimeType.JSON);
  }
  ```
</CodeGroup>

Ardından, projenizi dağıtın. Sağ üstteki Deploy'a tıklayın ve dağıtım türü olarak "Web App"'i seçin. Bir açıklama sağlayın ve projeye kimlerin erişebileceğini seçin; bir sonraki adımda gereken URL'yi oluşturmak için "Anyone"'ı seçeceğiz.

<Frame>
  <img src="https://mintcdn.com/onesignal/9_Q1FZLh6C0BFLq-/images/docs/bd7ac47-image3.png?fit=max&auto=format&n=9_Q1FZLh6C0BFLq-&q=85&s=2922ca6a7bcabac841936775ae76bd13" width="770" height="450" data-path="images/docs/bd7ac47-image3.png" />
</Frame>

## Event stream oluşturun

<Steps>
  <Step>
    OneSignal panosundan **Settings > Event Streams (ek özelliğe tabi)**'e gidin. Oradan yeni bir event stream oluşturun ve "Trigger when any of the following events occur" seçeneğini seçin. Google Sheets ile senkronize etmek istediğiniz mesaj olaylarını açılır pencerede seçin. Aşağıdaki örnekte, tüm Push Notification olaylarını yakalıyoruz.

    <Frame>
      <img src="https://mintcdn.com/onesignal/6tscVAtiSqz353kV/images/docs/9d0a4f6662d11217650e230f085b44d96110075c5f52db6f6dc48402e90c8831-Screenshot_2024-10-24_at_3.46.54_PM.png?fit=max&auto=format&n=6tscVAtiSqz353kV&q=85&s=a7b7b34db5a782a82139f547970dc521" width="1122" height="650" data-path="images/docs/9d0a4f6662d11217650e230f085b44d96110075c5f52db6f6dc48402e90c8831-Screenshot_2024-10-24_at_3.46.54_PM.png" />
    </Frame>
  </Step>

  <Step>
    Ardından, yapılandırma adımında POST'u seçin, önceki adımın URL'sini yapıştırın ve JSON'u kabul etmek için bir başlık oluşturun.

    <Frame>
      <img src="https://mintcdn.com/onesignal/Z6xkXGfmy814If53/images/docs/dcf540d-image1.png?fit=max&auto=format&n=Z6xkXGfmy814If53&q=85&s=2d5d107ddf7b46c76f5a2c25791b404a" width="959" height="385" data-path="images/docs/dcf540d-image1.png" />
    </Frame>
  </Step>

  <Step>
    Bundan sonra, Step 3 Dropdown'da "Custom Body"yi seçin ve aşağıdaki kodu kopyalayıp yapıştırın. Aşağıdaki örnekte gösterildiği gibi, senkronize etmek istediğiniz özellikleri ve olayları değiştirebilirsiniz. Event stream olay özellikleri hakkında daha fazla bilgi için [belgelerimizi](./event-streams#personalization) ziyaret edin

    <CodeGroup>
      ```json json theme={null}
      {
        "user_id": "{{ event.external_user_id }}",
        "event_id": "{{ event.id }}",
        "event": "{{ event.kind }}",
        "properties": {
          "message_id": "{{ message.id }}",
          "message_name": "{{ message.name }}",
          "message_title": "{{ message.title.en }}",
          "message_contents": "{{ message.contents.en }}",
          "template_id": "{{ message.template_id }}",
          "subscription_id": "{{ event.subscription_id }}",
          "subscription_device_type": "{{ event.subscription_device_type }}",
          "source": "onesignal"
        },
        "originalTimestamp": "{{ event.datetime }}"
      }
      ```
    </CodeGroup>
  </Step>

  <Step>
    Son olarak, seçilen mesaj olaylarını Google Sheet'e senkronize etmek için "Save & Activate"i seçin. Aşağıda, yukarıdaki örnek kodun nasıl göründüğüne dair bir örnek bulunmaktadır:

    <Frame>
      <img src="https://mintcdn.com/onesignal/Z6xkXGfmy814If53/images/docs/d8a0fc0-image2.png?fit=max&auto=format&n=Z6xkXGfmy814If53&q=85&s=fa26c2e16ff9b7435bcfe818cca8f9a5" width="960" height="265" data-path="images/docs/d8a0fc0-image2.png" />
    </Frame>
  </Step>
</Steps>

***
