@@ -133,9 +133,9 @@ def get_default_header(self):
133133
134134 def get_full_url (self , service_name , relative_url ):
135135 if self .api_location :
136- hostname = "%s- %s.%s" % (
136+ hostname = "%s%s.%s" % (
137137 self .api_location ,
138- service_name ,
138+ "" if service_name == "analytics" else f"- { service_name } " ,
139139 self .base_domain_name ,
140140 )
141141 elif service_name :
@@ -472,7 +472,7 @@ def create_redirect_url(self, target_url, user_id, events):
472472 params = dict (auth_type = "jwt" , authorization = auth_token , url = target_url )
473473 params ["api_key" ] = self .api_key
474474 params ["events" ] = json .dumps (events )
475- url = self .base_analytics_url + " redirect/"
475+ url = f" { self .base_analytics_url } redirect/"
476476 # we get the url from the prepare request, this skips issues with
477477 # python's urlencode implementation
478478 request = Request ("GET" , url , params = params )
@@ -481,6 +481,76 @@ def create_redirect_url(self, target_url, user_id, events):
481481 Request ("GET" , target_url ).prepare ()
482482 return prepared_request .url
483483
484+ def track_engagements (self , engagements ):
485+ """
486+ Creates a list of engagements
487+
488+ ;param engagements: Slice of engagements to create.
489+
490+ eg.
491+ [
492+ {
493+ "content": "1",
494+ "label": "click",
495+ "features": [
496+ {"group": "topic", "value": "js"},
497+ {"group": "user", "value": "tommaso"},
498+ ],
499+ "user_data": "tommaso",
500+ },
501+ {
502+ "content": "2",
503+ "label": "click",
504+ "features": [
505+ {"group": "topic", "value": "go"},
506+ {"group": "user", "value": "tommaso"},
507+ ],
508+ "user_data": {"id": "486892", "alias": "Julian"},
509+ },
510+ {
511+ "content": "3",
512+ "label": "click",
513+ "features": [{"group": "topic", "value": "go"}],
514+ "user_data": {"id": "tommaso", "alias": "tommaso"},
515+ },
516+ ]
517+ """
518+
519+ auth_token = self .create_jwt_token ("*" , "*" , feed_id = "*" )
520+ self .post (
521+ "engagement/" ,
522+ auth_token ,
523+ data = {"content_list" : engagements },
524+ service_name = "analytics" ,
525+ )
526+
527+ def track_impressions (self , impressions ):
528+ """
529+ Creates a list of impressions
530+
531+ ;param impressions: Slice of impressions to create.
532+
533+ eg.
534+ [
535+ {
536+ "content_list": ["1", "2", "3"],
537+ "features": [
538+ {"group": "topic", "value": "js"},
539+ {"group": "user", "value": "tommaso"},
540+ ],
541+ "user_data": {"id": "tommaso", "alias": "tommaso"},
542+ },
543+ {
544+ "content_list": ["2", "3", "5"],
545+ "features": [{"group": "topic", "value": "js"}],
546+ "user_data": {"id": "486892", "alias": "Julian"},
547+ },
548+ ]
549+ """
550+
551+ auth_token = self .create_jwt_token ("*" , "*" , feed_id = "*" )
552+ self .post ("impression/" , auth_token , data = impressions , service_name = "analytics" )
553+
484554 def og (self , target_url ):
485555 """
486556 Retrieve open graph information from a URL which you can
0 commit comments