Class: ShedCloud::PartnerApi::Resources::SiteEvents

Inherits:
Base
  • Object
show all
Defined in:
lib/shedcloud/partner_api/resources/site_events.rb

Overview

Visitor behavioral events from partner marketing sites.

Partner keys are server-side secrets: proxy events through your backend and never call these endpoints from the browser. Ingest is rate limited per company, so batch events client-side (max 25 per request). Always send a stable visitor_id — it stitches journeys across the marketing site and the 3D configurator. Raw events are retained ~90 days on reads.

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from ShedCloud::PartnerApi::Resources::Base

Instance Method Details

#each(params = {}) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/shedcloud/partner_api/resources/site_events.rb', line 30

def each(params = {})
  cursor = params[:cursor].to_s
  last_seen = cursor

  loop do
    page_params = params.dup
    if cursor.empty?
      page_params.delete(:cursor)
    else
      page_params[:cursor] = cursor
    end

    response = list(page_params)
    data = response['data'].is_a?(Array) ? response['data'] : []

    data.each do |event|
      result = yield(event)
      return last_seen if result == false

      last_seen = event['eventId'] if event['eventId'].is_a?(String) && !event['eventId'].empty?
    end

    break unless response['hasMore'] && response['nextCursor'].is_a?(String) && !response['nextCursor'].empty?

    cursor = response['nextCursor']
  end

  last_seen
end

#list(params = {}) ⇒ Object

GET /partner/v1/site-events (scope partner-api.site-events.read). Query params are camelCase on the wire: cursor, limit (max 200), sessionId, types, from, to.



24
25
26
27
28
# File 'lib/shedcloud/partner_api/resources/site_events.rb', line 24

def list(params = {})
  query = params.dup
  query[:types] = query[:types].join(',') if query[:types].is_a?(Array)
  @http.request('GET', '/partner/v1/site-events', query: query) || {}
end

#track(body, options: nil) ⇒ Object

POST /partner/v1/site-events (scope partner-api.site-events.write). Unlike most Partner API endpoints, the ingest body natively speaks snake_case on the wire (session_id, visitor_id, events.event_type, ...).



17
18
19
# File 'lib/shedcloud/partner_api/resources/site_events.rb', line 17

def track(body, options: nil)
  @http.request('POST', '/partner/v1/site-events', body: body, headers: option_headers(options)) || {}
end