Display Advertisement by Country Using ASP and COM Technology

Display ads based on visitor origin country

Online advertising is another way to promote company products. It’s very important to show the right advertisements to the right consumers to have an optimum response. A company selling their products in Japan showing their advertisement to visitors from United States is totally ineffective. On the other hand, localized advertisements catch visitor attention and improve sales.

In this example, we use a fully functional IP2Location™ ActiveX component available at https://www.ip2location.com/software/active-x to query country by visitor’s IP address. For unregistered component, there is a 5-second delay in every query. First, install the ActiveX component in IIS web server. It could be as simple as running a command in DOS prompt.

C:\> regsvr32 ip2location.dll

Sample Code:

<%
    ' Create server-side object
    Set ipObj = Server.CreateObject("IP2Location.Country")
 
    ' Initialize IP2Location object
    If ipObj.Initialize("demo") <> "OK" Then
        response.write "IP2Location Initialization Failed."
    End If
 
    ' Get visitor's IP address
    IPaddr = Request.ServerVariables("REMOTE_ADDR")
 
    ' Detect visitor's country of origin by IP address
    CountryName = ipObj.LookUpShortName(IPaddr)
 
    ' Free IP2Location object
    Set ipObj = nothing
 
    If CountryName = "JP" Then
        ' Visitor is from Japan
        ' Show advertisement from Japan
        response.write "<img src=\"Japan.jpg\" border=\"0\" width=\"100\" height=\"200\">"
    Else
        ' Visitor is not from Japan
        ' Show other advertisement
        response.write "<img src=\"US.jpg\" border=\"0\" width=\"100\" height=\"200\">"
    End If
%>

Was this article helpful?

Related Articles