Using The API Message Source To Track Web Events

You can use the API Message Source to track web events, such as web site visitor tracking or email view events (for example, to track when someone has viewed an email, newsletter etc).

The API Message Source will execute an Automation whenever the API URL is requested via HTTP GET or POST. The Automation itself can perform any actions (such as updating a database etc). The Automation can return a value that is returned as a response to the HTTP request, so for example, you could return a file path to an image file. If your Automation returns a file path, ThinkAutomation will automatically return the file content. This means you can use the API Message source that executes an Automation. The Automation can execute actions to track the visit request and then return a path to an image file - which would be displayed.

Example Automation for a Web Tracker that counts the visits for each unique IP address and saves the tracking info to a CSV file:


VisitNumber =  
BrowserName =  
Country =  

// Increment a visit count for the IP address
VisitNumber = Counter Increment Static RequestNumber (%Msg_FromIp%)

// Get browser name from User-Agent header using the Set Variable action with the Extract Header Value operation  
UserAgent = Extract Header Value (User-Agent)  
BrowserName = Get Browser Infor For %UserAgent%  

// Get Country Name from request IP address  
GeoIP Lookup %Msg_FromIp% Set %Country% = Country  

// Save request to CSV  
Update CSV D:\tracking\visitors.csv (IP,Browser,Country,Dated,Visit) = (%Msg_FromIp%,%BrowserName%,%Country%,%DateTime%,%VistNumber)  

// Return an image  
Return D:\tracking\logo.png  


You would then embed the Public API URL for the Message Source inside the HTML you want to track. You need to add the '&results=true' URL parameter so that the return value from the Automation is returned. 

If you wanted to track email views for a HTML email - then embed the Public API URL in your email HTML (with the &results=true querystring parameter). You include the recipient email address in the URL using the &from={email} querystring parameter. Inside your Automation this would be set to the %Msg_From% variable - which you can then use to record the read event in some way. 

You can add any other fields to the request URL in the form '&x-{fieldname}={value}' - these will then be added to the %Msg_Body% variable, which you can extract and use in your Automation.

For example, to embed the API request in an img tag: 

<img src="https://api.thinkautomation.com/addmessage?taid=636d2xxx&from=test%40test.com&x-PageName=newsletter&results=true">

Whenever the above image is requested in a web page or email your Automation will execute allowing you to track the event. Your Automation will need to return a path to an image file.

Note: The Public API limits daily requests (5000 for the Pro Edition, 1000 for Std). If you will be tracking more than this then you can host your own Gateway Instance - which has no limits (Professional Edition Only). You could also use the Local API URL - which has no limits, however your ThinkAutomation Server would need to be running on a machine that has a public IP/DNS name (and trusted SSL cert set in the ThinkAutomation Server settings).

Response Time

The response time for the request will depend on the Internet bandwidth available to your own ThinkAutomation Instance and what your Automation is doing (for example, if the Automation is updating a database that itself is slow). One way to ensure a fast response would be to simply save the request to a text file in the API Response Automation - and then have another ThinkAutomation 'File Pickup' Message Source pickup these and do the database processing separately.

Another factor will be how busy your ThinkAutomation Server is - IE: if your ThinkAutomation Server is already handling many other Message Sources/Automations then response time could be a factor. 

You should test response times before deployment.

api
Creation date: 10/08/2023 08:30      Updated: 10/08/2023 09:57