Skip to main content
All CollectionsAccount & SetupPerform
Create your own custom login page
Create your own custom login page

Use our API to create a versatile custom login page on your own website

Matthew Davis avatar
Written by Matthew Davis
Updated over 2 months ago

By using our API, it's possible to create your own custom login page on your website.

Benefits of creating your own custom login page include:

  • Tie into your existing website or CRM (client relationship management) software

  • Style your login area to match your exact design specifications

  • Change the behavior of the way your clients log in and which page they land on

You will need access to the API which is only available on some plans.
โ€‹View the API information here.

Note: Due to the unique ways in which a website can be set up to use the API, our Support staff do not assist with API troubleshooting. We recommend to hire a professional Web Developer to handle the API for you.

How to create your own custom login page

First, you will need to find your API key in order to make API requests.

This is located under your profile settings. For more information view this resource article.

The basic process to create a functioning custom login page is as follows:

  1. Authenticate the user on your end

  2. Get the user list from your AgencyAnalytics account using the API

  3. Match the user ID

  4. Generate the login grant for that user ID via the API

  5. Redirect to the URL provided by the API response

Authenticate the user on your end

This step is entirely dependent on the way your existing website is setup, and what CMS (content management system) it is using.

For example, for a Wordpress CMS, you can use the wp_authenticate function to check whether the login is valid or not; and if the user logs in successfully, continue.

wp_authenticate($username, $password);

Get the user list from your AgencyAnalytics account using the API

Perform a request to list all users.

{
"provider": "agency-analytics-v2",
"asset": "user",
"operation": "read",
"fields": [
"id",
"campaign_id",
"date_created",
"date_modified",
"email",
"first_name",
"last_name",
"role",
"campaign_access",
"status",
"account_id"
],
"sort": [
{
"id": "desc"
}
],
"offset": 0,
"limit": 50
}

The response will be in JSON format and will be similar to the below:

 {
"metadata": {
"total_pages": 1,
"total_records": 2
},
"data": [
{
"id": 123,
"date_created": "2015-03-30 10:06:24",
"email": "bob@myagency.com",
"username": "bob@myagency.com",
"password": null,
"first_name": "Bob",
"last_name": "Doe",
"role": "client",
"campaign_access": "restricted",
"account_id": 1
},
{
"id": 124,
"date_created": "2015-03-30 10:06:25",
"email": "alice@myagency.com",
"username": "alice@myagency.com",
"password": null,
"first_name": "Alice",
"last_name": "Citizen",
"role": "client",
"campaign_access": "restricted",
"account_id": 1
}
]
}

Match the user ID

Here is where you will need to match the username that was entered into your form with the username from the user list that was provided by the API response.

It's recommended to use email addresses as the usernames, because AgencyAnalytics uses them and therefore they will match up quite easily. However this will not be possible in every circumstance (depending how your own customer database is set up).

Generate the login grant for that user ID via the API

Now that the user ID (123) has been retrieved for the specific user that is trying to login, you can generate the login grant via the API.

{
"provider": "agency-analytics-v2",
"asset": "login-grant",
"operation": "create",
"rows": [
{
"user_id": "123"
}
]
}

Response:

{
"metadata": {
"total_pages": 1,
"total_records": 1
},
"data": {
"token": "tkn.7bf94c2ks9f2e7d86174a4b3fc01c5ae",
"time": "2015-04-13 16:34:57",
"login_url": "http:\/\/reports.myagency.com\/login-token\/tkn.c6e1768b8e01ddwq2461ace8886b",
"user_id": 123,
"origin_user_id": 1
}
}

Redirect to the URL provided by the API response

With that API response you can extract the login URL.

http://reports.myagency.com/login-token/tkn.c6e1768b8e01ddwq2461ace8886b

Finally, the user can be sent to their client area by using one of the many redirect methods.

Did this answer your question?