Implementing Server to Server Events

Pass event data directly to Elevar from your server

Overview

After completing your browser setup, you may chose to setup up server-to-server data processing to pass data via the API directly to from your server to Elevar's server. You will need to build the event payload in the required shape for the event data to be accepted via Elevar's Server.


Implementing Server to Server Events

Build the Server Request

  • You will need to build the request that will be sent to the Elevar server. Follow the formatting below. Find the values as shown in Figure 2 below.
fetch("{{insert Enpoint URL here}}?signature={{insert signing key here}}", {
  headers: {
    "X-Website-ID": "{{insert website ID value here}}"
  },
  body: JSON.stringify({
    //See purchase event payload below
  })
})

Locate the Your Request Values

Access API Source:

  • Begin on your Elevar homepage and use the left-hand navigational menu to click on the "My Tracking" tab.
  • Navigate to the Sources section of the page and click on the box labeled "API".
    • (See Figure 1)

Step 1 screenshot

_Figure 1_

Locate Server Setup:

  • Navigate to the section of the page titled "Endpoint URL" and click on the "Copy to Clipboard" button. Follow the guide to set up server-to-server data processing.
  • Navigate to the section of the page titled "Website ID" and click on the "Copy to Clipboard" button. Follow the guide to set up server-to-server data processing.
  • Navigate to the section of the page titled "Signing Key" and click on the "Copy to Clipboard" button. Follow the guide to set up server-to-server data processing.
  • Once you have prepared your server to server events setup, click on the "Mark as Complete" button located at the bottom of this section.
    • (See Figure 2)

Step 6 screenshot

_Figure 2_

Add the Purchase Event Payload

  • The Purchase event dl_purchase: Should fire when a user completes their purchase. This server-side event should only ever be sent once for each purchase.
let products = [];
let userProperties = {};

/** Purchase **/
    event: "dl_purchase",
    marketing: {
        landing_site: "https://example.com/store/product-a?utm_source=web&utm_campaign=spring"// The first page that the user landed on when they visited your site with query parameters,
    },
    user_properties: userProperties,
    ecommerce: {
        currencyCode: "USD",
        purchase: {
            actionField: {
                id: "4835925655784", // Order ID
                order_name: "#1005", // Order User-Friendly ID
                revenue: "185.3", // Revenue
                tax: "15.3",
                shipping: "0.0",
                affiliation: "staging-fully-managed-ga4-all-events", // Store name
                sub_total: "170.0", // Sub total
                product_sub_total: "170.0", // Product Sub total
                discount_amount: "0.0"
            },
            products: products
        }
    }

Reference:

/** Products Array **/
const products = [
	{
		id: "LB00161-34689553170476", // SKU
    name: "Lovebox Original Color & Photo", // Product title
    brand: "Lovebox INC",
    category: "Home,Living,Art & Objects,Tabletop",
    variant: "USA wall plug",
    price: "119.99",
    quantity: "1", // Not required for dl_select_item & dl_view_item
		position: "1", // Position in checkout starting at 1
    list: "/art/wallhangings", // The list the product was discovered from
    product_id: "6979886940352", // The product_id
    variant_id: "41141193965760", // id or variant_id
    compare_at_price: "139.99", // If available on dl_view_item & dl_add_to_cart otherwise use "0.0"
    image: "//cdn.shopify.com/small.png", // If available, otherwise use an empty string
		inventory: "5" // If available, only required on dl_view_item
	},
  ...
]

/** User Properties Object **/
// The majority of this information can only be retrieved for a logged in user
const userProperties = {
	// The following fields aren't required if unavailable
  customer_address_1: "1 Hills Plantation Drive",
	customer_address_2: "",
	customer_city: "Charleston",
	customer_country: "United States",
	customer_email: "[email protected]",
	customer_first_name: "Bill",
	customer_id: "5928549548188",
	customer_last_name: "Call",
	customer_order_count: "1",
	customer_phone: "999-999-9999",
	customer_province: "South Carolina",
	customer_province_code: "SC",
	customer_tags: "",
	customer_total_spent: "0.0",
	customer_zip: "22222",

  // The following fields are required 
	user_consent: "", // Use an empty string
	visitor_type: "logged_in" // "logged_in" || "guest"
}