Sha256: 721050fd15c7eee13c04cb81ff258110f9ffae4f88049117ff4875f658c4c400

Contents?: true

Size: 1.63 KB

Versions: 26

Compression:

Stored size: 1.63 KB

Contents

# Copyright (c) 2015 Sqreen. All Rights Reserved.
# Please refer to our terms for more information: https://www.sqreen.io/terms.html

# Sqreen Namespace
module Sqreen

  SDK_RESERVED_PREFIX = 'sq.'.freeze
  TRACK_PAYLOAD_DATA = ['request'.freeze, 'params'.freeze, 'headers'.freeze].freeze

  # Sqreen SDK
  class << self
    # Authentication tracking method
    def auth_track(is_logged_in, authentication_keys); end

    def signup_track(authentication_keys); end

    def identify(authentication_keys, traits = {})
      return unless Sqreen.framework
      Sqreen.framework.observe(
        :sdk,
        [:identify, Time.now, authentication_keys, traits],
        [], false
      )
    end

    def track(event_name, options = {})
      return unless Sqreen.framework
      if event_name.start_with? SDK_RESERVED_PREFIX
        Sqreen.log.warn("Event names starting with '#{SDK_RESERVED_PREFIX}' " \
                        'are reserved. Event ignored.')
        return false
      end
      internal_track(event_name, options)
    end

    # For internal usage. Users are to call track() instead.
    def internal_track(event_name, options = {})
      properties = options[:properties]
      user_identifiers = options[:user_identifiers]
      timestamp = options[:timestamp] || Time.now.utc
      # Not in SDK v0
      # request = options[:request]

      args = {}
      args[:user_identifiers] = user_identifiers if user_identifiers
      args[:properties] = properties if properties

      Sqreen.framework.observe(
        :sdk,
        [:track, timestamp, event_name, :args => args],
        TRACK_PAYLOAD_DATA, true
      )
      true
    end
  end
end

Version data entries

26 entries across 26 versions & 2 rubygems

Version Path
sqreen-1.15.2 lib/sqreen/sdk.rb
sqreen-1.15.1 lib/sqreen/sdk.rb
sqreen-1.15.0-java lib/sqreen/sdk.rb
sqreen-1.15.0 lib/sqreen/sdk.rb
sqreen-1.14.2-java lib/sqreen/sdk.rb
sqreen-1.14.2 lib/sqreen/sdk.rb
sqreen-1.14.1-java lib/sqreen/sdk.rb
sqreen-1.14.1 lib/sqreen/sdk.rb
sqreen-1.14.0-java lib/sqreen/sdk.rb
sqreen-1.14.0 lib/sqreen/sdk.rb
sqreen-1.14.0.beta3-java lib/sqreen/sdk.rb
sqreen-1.14.0.beta3 lib/sqreen/sdk.rb
sqreen-1.14.0.beta2 lib/sqreen/sdk.rb
sqreen-1.14.0.beta1 lib/sqreen/sdk.rb
sqreen-1.13.4-java lib/sqreen/sdk.rb
sqreen-alt-1.13.4 lib/sqreen/sdk.rb
sqreen-1.13.4 lib/sqreen/sdk.rb
sqreen-1.13.2-java lib/sqreen/sdk.rb
sqreen-alt-1.13.2 lib/sqreen/sdk.rb
sqreen-1.13.2 lib/sqreen/sdk.rb