Package: interakt-track-python
Interakt Track PythonSDK :interakt-track-pythonGetting StartedInstallinterakt-track-pythonusing pippip install interakt-track-pythonAuthenticationInside your app, you’ll want to set yourapi_keybefore making any track calls:To find your API key,go to your interakt account's Settings --> Developer Settingscopy the Secret Key.Make sure you base64 decode this Secret Key (you may choose to do that fromBase64 Decode and Encode- online)Erase the ':' at the end of the base64 decoded keyUse this keyimport track

track.api_key =  "YOUR_API_KEY"Development SettingsThe default initialization settings are production-ready and queue messages to be processed by a background thread.In development you might want to enable some settings to make it easier to spot problems. Enablingtrack.debugwill log debugging info to the Python logger. You can also add anon_errorhandler to specifically print out the response you’re seeing from our API.def on_error(error, queue_msg):
    print("An error occurred", error)
    print("Queue message", queue_msg)

track.debug = True
track.on_error = on_errorAll Settings:Settings nameTypeDefault valueDescriptionsync_modeboolFalseWhenTrue, calls the track APIsynchronously. WhenFalse, calls the track APIsasynchronouslyusing a Queue.debugboolFalseTo turn on debug loggingtimeoutint10Timout for track API callsmax_retriesint3Number of API retries in case API call fails due to some errormax_queue_sizeint10000Max Queue sizeon_errorfunctionNoneCallback function which is called whenever an error occurs inasynchronousmodeAPIsUserThe user track API allows customers to record the attributes specific to the user. They can record specific user properties (attributes) such as user id, email id, phone number, name etc. Customers can call the usertrack API when a new user account is created on their website/app/CRM. For example:For adding a new user to your interakt dashboard, the following payload could be sent in the API call:track.user(
	user_id="<user_id in your db>",
	country_code="+91",
	phone_number="9999999999",
	traits={
		"name": "John Doe",
		"email": "john@email.com",
		"age": 24,
		“dob”: “1998-01-01”
	}
)The different user attributes (traits) can be of the following data types: String, Numbers, Boolean, Datetime, List.Check out the different filter options available in interakt, for different trait types -link.
‍Note**: Specifying either theuser IdorphoneNumber (with countryCode)isMandatory‍The above API call records the “userId” or “phoneNumber” (with “countryCode”) as a unique identifier for the user and also adds attributes such as name, email, dob.Event PropertyTypeStatusDescriptionuser_idStringOptional**The userId can take any string value that you specify. This will henceforth be used as a unique identifier for the user.The user id parameter will remain the same throughout the lifetime of the customer & cannot be updated. It is recommended that you use your database id instead of a plain username, as database ids generally never change.phone_numberStringMandatory**phone number of the user without the country code (we recommend that you send the Whatsapp phone number of the user, so that you can send messages to that user via interakt, else the messages won’t get sent)country_codeStringMandatory**Country code of the phone number. The default value is “+91”.traitsObjectOptionalUser attributes such as name, email id etc.created_atDateOptionalTimestamp of the event in ISO-8601 format date string. If you have not passed the “createdAt” property, we will automatically use the current utc server time as the value of “createdAt”To update attributes for the above user, the following payload could be sent in the API call: (suppose the “dob” attribute needs to be changed to “1997-12-01”).
‍track.user(
	user_id="<user_id in your db>",
	country_code="+91",
	phone_number="9999999999",
	traits={
        “dob”: “1997-12-01”
    }
)‍To add a new attribute for the above user, the following payload could be sent in the API call: (suppose the “pin code” attribute needs to be added).
‍track.user(
	user_id="<user_id in your db>",
	country_code="+91",
	phone_number="9999999999",
	traits={
    	“Pin code”: “400001”
    }
)‍
‍Note:In case, the above user had originally been added via the interakt dashboard (and not by calling the User Track API), then, no userId would exist for that user. In that case, you could either:Call the User Track API without specifying a “userId” (and only specifying the “phoneNumber” & “countryCode”), or,Include a userId in the API call, which will then get added for that user, and you could use that userId to reference that user in future API calls.*
‍Currently, we don’t provide the option for deleting any user / user attribute.*Please make sure the added userId doesn’t belong to an already existing user in your interakt account, else the API will throw an error.EventThe event track API allows customers to record user actions. Each user action (such as a new order created, new user sign up, and so on) will trigger an event to the endpoint. For example:For adding a new event for a particular user, the following payload could be sent in the API call:track.event(
	user_id="<user id in your db>",
	event="Order Placed",
	“traits”={
		“orderCreatedBy”: “Gavin Roberts”,
		“orderCreatedDate”: “2020-11-01T012:10:26.122Z”,
		“orderNumber”: “CUS001”,
		“orderValue”: “50.00”
	},
	country_code="+91",
	phone_number="9999999999",
)The above API call triggers an OrderPlaced event when your user makes an order on your website/app. The API call passes the event properties orderCreatedBy, orderCreatedDate, orderNumber and orderValue to the API endpoint.
‍Please note:In case userId doesn't exist for a user, "phoneNumber" & "countryCode" would need to be specified in the above Event Track API Call.Event PropertyTypeStatusDescriptionuser_idStringOptionalUnique identifier for the user.eventStringOptionalThe action that the user has performed. It’s important to give meaningful names for your events. Example: OrderCreated, NewSignUp, OrderExecuted, etc.traitsObjectOptionalProperties are additional bits of information corresponding to the user action that is performed. They provide detailed information about user actions.created_atDateOptionalTimestamp of the event in ISO-8601 format date string. If you have not passed the “createdAt” property, we will automatically use the current utc server time as the value of “createdAt”phone_numberStringMandatory**phone number of the user without the country code (we recommend that you send the Whatsapp phone number of the user, so that you can send messages to that user via interakt, else the messages won’t get sent)country_codeStringMandatory**Country code of the phone number. The default value is “+91”.