def track_struct_event(self,
                           category,
                           action,
                           label=None,
                           property_=None,
                           value=None,
                           context=None,
                           tstamp=None):
        """
            :param  category:       Category of the event
            :type   category:       non_empty_string
            :param  action:         The event itself
            :type   action:         non_empty_string
            :param  label:          Refer to the object the action is
                                    performed on
            :type   label:          string_or_none
            :param  property_:      Property associated with either the action
                                    or the object
            :type   property_:      string_or_none
            :param  value:          A value associated with the user action
            :type   value:          int | float | None
            :param  context:        Custom context for the event
            :type   context:        context_array | None
            :rtype:                 tracker
        """
        pb = payload.Payload()
        pb.add("e", "se")
        pb.add("se_ca", category)
        pb.add("se_ac", action)
        pb.add("se_la", label)
        pb.add("se_pr", property_)
        pb.add("se_va", value)

        return self.complete_payload(pb, context, tstamp)
    def track_page_view(self,
                        page_url,
                        page_title=None,
                        referrer=None,
                        context=None,
                        tstamp=None):
        """
            :param  page_url:       URL of the viewed page
            :type   page_url:       non_empty_string
            :param  page_title:     Title of the viewed page
            :type   page_title:     string_or_none
            :param  referrer:       Referrer of the page
            :type   referrer:       string_or_none
            :param  context:        Custom context for the event
            :type   context:        context_array | None
            :param  tstamp:         Optional user-provided timestamp for the event
            :type   tstamp:         timestamp | int | float | None
            :rtype:                 tracker
        """
        pb = payload.Payload()
        pb.add("e", "pv")  # pv: page view
        pb.add("url", page_url)
        pb.add("page", page_title)
        pb.add("refr", referrer)

        return self.complete_payload(pb, context, tstamp)
Пример #3
0
 def test_object_generation_2(self):
     p = payload.Payload({
         "test1": "result1",
         "test2": "result2",
     })
     output = {"test1": "result1", "test2": "result2"}
     self.assertTrue(is_subset(output, p.nv_pairs))
Пример #4
0
    def track_page_ping(self, page_url, page_title=None, referrer=None, min_x=None, max_x=None, min_y=None, max_y=None, context=None, tstamp=None):
        """
            :param  page_url:       URL of the viewed page
            :type   page_url:       non_empty_string
            :param  page_title:     Title of the viewed page
            :type   page_title:     string_or_none
            :param  referrer:       Referrer of the page
            :type   referrer:       string_or_none
            :param  min_x:          Minimum page x offset seen in the last ping period
            :type   min_x:          int | None
            :param  max_x:          Maximum page x offset seen in the last ping period
            :type   max_x:          int | None
            :param  min_y:          Minimum page y offset seen in the last ping period
            :type   min_y:          int | None
            :param  max_y:          Maximum page y offset seen in the last ping period
            :type   max_y:          int | None
            :param  context:        Custom context for the event
            :type   context:        context_array | None
            :param  tstamp:         Optional user-provided timestamp for the event
            :type   tstamp:         timestamp | int | float | None
            :rtype:                 tracker
        """
        pb = payload.Payload()
        pb.add("e", "pp")           # pp: page ping
        pb.add("url", page_url)
        pb.add("page", page_title)
        pb.add("refr", referrer)
        pb.add("pp_mix", min_x)
        pb.add("pp_max", max_x)
        pb.add("pp_miy", min_y)
        pb.add("pp_may", max_y)

        return self.complete_payload(pb, context, tstamp)
Пример #5
0
    def track_ecommerce_transaction(self, order_id, total_value, affiliation=None,
                                    tax_value=None, shipping=None, city=None, state=None,
                                    country=None,  currency=None, items=None,
                                    context=None, tstamp=None, event_subject=None):
        """
            :param  order_id:       ID of the eCommerce transaction
            :type   order_id:       non_empty_string
            :param  total_value:    Total transaction value
            :type   total_value:    int | float
            :param  affiliation:    Transaction affiliation
            :type   affiliation:    string_or_none
            :param  tax_value:      Transaction tax value
            :type   tax_value:      int | float | None
            :param  shipping:       Delivery cost charged
            :type   shipping:       int | float | None
            :param  city:           Delivery address city
            :type   city:           string_or_none
            :param  state:          Delivery address state
            :type   state:          string_or_none
            :param  country:        Delivery address country
            :type   country:        string_or_none
            :param  currency:       The currency the price is expressed in
            :type   currency:       string_or_none
            :param  items:          The items in the transaction
            :type   items:          list(dict(str:*)) | None
            :param  context:        Custom context for the event
            :type   context:        context_array | None
            :param  tstamp:         Optional event timestamp in milliseconds
            :type   tstamp:         int | float | None
            :param  event_subject:  Optional per event subject
            :type   event_subject:  subject | None
            :rtype:                 tracker
        """
        pb = payload.Payload()
        pb.add("e", "tr")
        pb.add("tr_id", order_id)
        pb.add("tr_tt", total_value)
        pb.add("tr_af", affiliation)
        pb.add("tr_tx", tax_value)
        pb.add("tr_sh", shipping)
        pb.add("tr_ci", city)
        pb.add("tr_st", state)
        pb.add("tr_co", country)
        pb.add("tr_cu", currency)

        tstamp = Tracker.get_timestamp(tstamp)

        self.complete_payload(pb, context, tstamp, event_subject)

        if items is None:
            items = []
        for item in items:
            item["tstamp"] = tstamp
            item["event_subject"] = event_subject
            item["order_id"] = order_id
            item["currency"] = currency
            self.track_ecommerce_transaction_item(**item)

        return self
Пример #6
0
 def test_add_dict(self):
     p = payload.Payload({
         "n1": "v1",
         "n2": "v2",
     })
     p.add_dict({"name4": 4, "name3": 3})  # Order doesn't matter
     output = {"n1": "v1", "n2": "v2", "name3": 3, "name4": 4}
     self.assertTrue(is_subset(output, p.nv_pairs))
Пример #7
0
 def test_add(self):
     p = payload.Payload()
     p.add("name1", "value1")
     p.add("name2", "value2")
     output = {
         "name1": "value1",
         "name2": "value2",
     }
     self.assertTrue(is_subset(output, p.nv_pairs))
    def track_ecommerce_transaction_item(self,
                                         order_id,
                                         sku,
                                         price,
                                         quantity,
                                         name=None,
                                         category=None,
                                         currency=None,
                                         context=None,
                                         tstamp=None):
        """
            This is an internal method called by track_ecommerce_transaction.
            It is not for public use.

            :param  order_id:    Order ID
            :type   order_id:    non_empty_string
            :param  sku:         Item SKU
            :type   sku:         non_empty_string
            :param  price:       Item price
            :type   price:       int | float
            :param  quantity:    Item quantity
            :type   quantity:    int
            :param  name:        Item name
            :type   name:        string_or_none
            :param  category:    Item category
            :type   category:    string_or_none
            :param  currency:    The currency the price is expressed in
            :type   currency:    string_or_none
            :param  context:     Custom context for the event
            :type   context:     context_array | None
            :rtype:              tracker
        """
        pb = payload.Payload()
        pb.add("e", "ti")
        pb.add("ti_id", order_id)
        pb.add("ti_sk", sku)
        pb.add("ti_nm", name)
        pb.add("ti_ca", category)
        pb.add("ti_pr", price)
        pb.add("ti_qu", quantity)
        pb.add("ti_cu", currency)

        return self.complete_payload(pb, context, tstamp)
Пример #9
0
    def track_unstruct_event(self, event_json, context=None, tstamp=None):
        """
            :param  event_json:      The properties of the event. Has two field:
                                     A "data" field containing the event properties and
                                     A "schema" field identifying the schema against which the data is validated

            :type   event_json:      dict(string: string | dict)
            :param  context:         Custom context for the event
            :type   context:         list(dict(string:*)) | None
            :rtype:                  tracker
        """

        envelope = {"schema": UNSTRUCT_EVENT_SCHEMA, "data": event_json}

        pb = payload.Payload()

        pb.add("e", "ue")
        pb.add_json(envelope, self.encode_base64, "ue_px", "ue_pr")

        return self.complete_payload(pb, context, tstamp)
Пример #10
0
    def track_unstruct_event(self, event_json, context=None, tstamp=None):
        """
            :param  event_json:      The properties of the event. Has two field:
                                     A "data" field containing the event properties and
                                     A "schema" field identifying the schema against which the data is validated

            :type   event_json:      self_describing_json
            :param  context:         Custom context for the event
            :type   context:         context_array | None
            :rtype:                  tracker
        """

        envelope = SelfDescribingJson(UNSTRUCT_EVENT_SCHEMA, event_json.to_json()).to_json()

        pb = payload.Payload()

        pb.add("e", "ue")
        pb.add_json(envelope, self.encode_base64, "ue_px", "ue_pr")

        return self.complete_payload(pb, context, tstamp)
Пример #11
0
    def track_page_view(self,
                        page_url,
                        page_title=None,
                        referrer=None,
                        context=None,
                        tstamp=None):
        """
            :param  page_url:       URL of the viewed page
            :type   page_url:       non_empty_string
            :param  page_title:     Title of the viewed page
            :type   page_title:     string_or_none
            :param  referrer:       Referrer of the page
            :type   referrer:       string_or_none
            :param  context:        Custom context for the event
            :type   context:        list(dict(string:*)) | None
            :rtype:                 tracker
        """
        pb = payload.Payload()
        pb.add("e", "pv")  # pv: page view
        pb.add("url", page_url)
        pb.add("page", page_title)
        pb.add("refr", referrer)

        return self.complete_payload(pb, context, tstamp)
Пример #12
0
 def test_object_generation(self):
     p = payload.Payload()
     self.assertTrue(is_subset({}, p.nv_pairs))
    def track_ecommerce_transaction(self,
                                    order_id,
                                    total_value,
                                    affiliation=None,
                                    tax_value=None,
                                    shipping=None,
                                    city=None,
                                    state=None,
                                    country=None,
                                    currency=None,
                                    items=None,
                                    context=None,
                                    tstamp=None):
        """
            :param  order_id:       ID of the eCommerce transaction
            :type   order_id:       non_empty_string
            :param  total_value: Total transaction value
            :type   total_value: int | float
            :param  affiliation: Transaction affiliation
            :type   affiliation: string_or_none
            :param  tax_value:   Transaction tax value
            :type   tax_value:   int | float | None
            :param  shipping:    Delivery cost charged
            :type   shipping:    int | float | None
            :param  city:        Delivery address city
            :type   city:        string_or_none
            :param  state:       Delivery address state
            :type   state:       string_or_none
            :param  country:     Delivery address country
            :type   country:     string_or_none
            :param  currency:    The currency the price is expressed in
            :type   currency:    string_or_none
            :param  items:          The items in the transaction
            :type   items:          list(dict(str:*))
            :param  context:        Custom context for the event
            :type   context:        list(dict(string:*)) | None
            :rtype:                 tracker | dict(string:*)
        """
        pb = payload.Payload()
        pb.add("e", "tr")
        pb.add("tr_id", order_id)
        pb.add("tr_tt", total_value)
        pb.add("tr_af", affiliation)
        pb.add("tr_tx", tax_value)
        pb.add("tr_sh", shipping)
        pb.add("tr_ci", city)
        pb.add("tr_st", state)
        pb.add("tr_co", country)
        pb.add("tr_cu", currency)

        tstamp = Tracker.get_timestamp(tstamp)

        transaction_result = self.complete_payload(pb, context, tstamp)

        item_results = []

        for item in items:
            item["tstamp"] = tstamp
            item["order_id"] = order_id
            item["currency"] = currency
            item_results.append(self.track_ecommerce_transaction_item(**item))

        if not isinstance(transaction_result, Tracker):
            return {
                "transaction_result": transaction_result,
                "item_results": item_results
            }
        else:
            return self