Class: Kameleoon::PageView

Inherits:
DuplicationSafeData show all
Defined in:
lib/kameleoon/data/page_view.rb

Overview

Represents page view data for tracking calls

Instance Attribute Summary collapse

Attributes inherited from Data

#instance

Instance Method Summary collapse

Methods inherited from Data

#mark_as_sent, #mark_as_transmitting, #mark_as_unsent, #sent, #transmitting, #unsent

Constructor Details

#initialize(url, title = nil, referrers = nil) ⇒ PageView

Returns a new instance of PageView.

Parameters:

  • url (String)

    Url of the page

  • title (String) (defaults to: nil)

    Optional field - title of the page

  • referrers (Array) (defaults to: nil)

    Optional field - Referrer ids



20
21
22
23
24
25
26
# File 'lib/kameleoon/data/page_view.rb', line 20

def initialize(url, title = nil, referrers = nil)
  super(DataType::PAGE_VIEW)
  @url = url || ''
  Logging::KameleoonLogger.error('Url for PageView is required parameter, the data will be ignored.') if @url == ''
  @title = title || ''
  @referrers = referrers.instance_of?(Integer) ? [referrers] : referrers
end

Instance Attribute Details

#referrerObject (readonly)

Returns the value of attribute referrer.



11
12
13
# File 'lib/kameleoon/data/page_view.rb', line 11

def referrer
  @referrer
end

#titleObject (readonly)

Returns the value of attribute title.



11
12
13
# File 'lib/kameleoon/data/page_view.rb', line 11

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



11
12
13
# File 'lib/kameleoon/data/page_view.rb', line 11

def url
  @url
end

Instance Method Details

#obtain_full_post_text_lineObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kameleoon/data/page_view.rb', line 28

def obtain_full_post_text_line
  params = {
    eventType: 'page',
    href: @url,
    title: @title,
    nonce: nonce
  }
  params[:referrersIndices] = "[#{@referrers.each(&:to_s).join(',')}]" if
    !@referrers.nil? && !@referrers.empty?
  Kameleoon::Network::UriHelper.encode_query(params)
end

#to_sObject



13
14
15
# File 'lib/kameleoon/data/page_view.rb', line 13

def to_s
  "PageView{url:'#{@url}',title:'#{@title}',referrers:#{@referrers}}"
end