Skip to content

How to import existing data ​

Integrating SimpleStats into your existing application doesn't mean leaving behind your historical data. Recognizing the value of your application's past insights, we've developed the Data Import feature. This functionality enables a smooth transition by allowing you to seamlessly import your existing data into SimpleStats, ensuring that you retain access to all historical metrics and insights.

INFO

The Data Import feature is not available on the free subscription plan.

Supported Formats ​

The Data Import supports the following file formats: xls, xlsx and csv.

Import Capabilities ​

The import feature is designed to manage substantial volumes of data efficiently. Therefore, unless you approach the limits of your subscription, we encourage you to import the entirety of your data. This capability ensures that you can leverage the full extent of your historical insights without reservations.

Importing User Data ​

Though it is not mandatory, it's highly recommended to first import the user data and only then the corresponding payment data. To start a new import, you have to provide a supported file format containing the user data to import.

Allowed User Fields ​

The following fields are allowed:

Core fields:

KeyTypeDescription
idmixed requiredThe user id.
timestring requiredThe time when the user has registerd.
Format: Y-m-d H:i:s, before or equal now
Optional fields
KeyTypeDescription
ipstring nullableThe ip of the user. (does not get stored)
user_agentstring nullableThe user_agent of the user. (does not get stored)
track_refererstring nullableThe tracking referer of the user.
track_sourcestring nullableThe tracking source of the user.
track_mediumstring nullableThe tracking medium of the user.
track_campaignstring nullableThe tracking campaign of the user.
track_termstring nullableThe tracking term of the user.
track_contentstring nullableThe tracking content of the user.
location_countrystring nullableThe location country of the user. (If the ip is set, we take the country that refers to it.)
location_regionstring nullableThe location region of the user. (If the ip is set, we take the region that refers to it.)
location_citystring nullableThe location city of the user. (If the ip is set, we take the city that refers to it.)
device_typestring nullableThe device type of the user. (If the user_agent is set, we take the device type that refers to it.)
device_platformstring nullableThe device platform (OS) of the user. (If the user_agent is set, we take the device platform that refers to it.)
device_browserstring nullableThe device browser of the user. (If the user_agent is set, we take the device browser that refers to it.)
page_entrystring nullableThe page entry point of the user.

Here is an example of how such an SQL query may look like:

sql
SELECT
    id,
    DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s') AS `time`
FROM
    users;
sql
SELECT
    id,
    to_char(created_at, 'YYYY-MM-DD HH24:MI:SS') AS "time"
FROM
    users;

With Condition ​

Sometimes you may not want to count all users as "valid" registrations. So you may only export the users which pass a certain condition, such as the user has verified their email address.

The query could look like this:

sql
SELECT
    id,
    DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s') AS `time`
FROM
    users
WHERE
    email_verified_at IS NOT NULL;
sql
SELECT
    id,
    to_char(created_at, 'YYYY-MM-DD HH24:MI:SS') AS "time"
FROM
    users
WHERE
    email_verified_at IS NOT NULL;

Now export the output of the query, save the file and then you can upload the file inside the app to start a new import!

INFO

Please note, the provided queries serve merely as examples. Your actual table structures and data might vary significantly. The implementation is completely up to you!

WARNING

The first row of your import file must be a heading row (a row in which each cell contains the key of the allowed fields)!

Simulated Natural Login Behavior (SNLB) ​

In many cases, historical login data for users isn't readily available. Without logins, activity metrics like DAU/WAU/MAU stay empty for the imported period. To address this, your user import file may optionally include a last_known_activity column. This field could correspond to the updated_at attribute, a last_login field, or any similar date in your users table that best approximates the user's most recent activity.

By supplying this information, we generate simulated login entries to mimic natural login patterns, based on the assumption that each user logged in at least once a week from their registration date to their last known activity. This provides a richer, more accurate representation of your historical user engagement over time.

KeyTypeDescription
last_known_activitystring nullableThe time of the user's most recent activity.
Format: Y-m-d H:i:s, must be equal or after time

How it works:

  • The first simulated login is placed at the registration time, followed by logins at least once a week with natural variation, and a final login exactly at last_known_activity.
  • Values in the future are clamped to the current time.
  • Users that already have login data are skipped, so re-imports won't create duplicates.
  • Rolling back the import also removes the generated logins.

Here is an example of how the SQL query from above may look like with SNLB:

sql
SELECT
    id,
    DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s') AS `time`,
    DATE_FORMAT(updated_at, '%Y-%m-%d %H:%i:%s') AS `last_known_activity`
FROM
    users;
sql
SELECT
    id,
    to_char(created_at, 'YYYY-MM-DD HH24:MI:SS') AS "time",
    to_char(updated_at, 'YYYY-MM-DD HH24:MI:SS') AS "last_known_activity"
FROM
    users;

Importing Payment Data ​

After you've imported your user data, you may start another import for your payment data. Again you have to provide a supported file format containing the payment data to import.

Allowed Payment Fields ​

The following fields are allowed:

KeyTypeDescription
idmixed requiredThe payment id.
stats_user_idinteger requiredThe user id associated with the payment.
timestring requiredThe time when the payment happened.
Format: Y-m-d H:i:s, before or equal now
grossnumeric requiredThe gross amount of the payment in cents.
(e.g.: $1 = 100 Cent)
netnumeric requiredThe net amount of the payment in cents.
(e.g.: $1 = 100 Cent).
currencystring requiredThe ISO-4217 currency code of the payment.
(e.g.: EUR, USD, GBP ...)
subscription_intervalstring nullableThe billing interval for subscription payments: month or year. Omit or null for one-time payments.
subscription_planstring nullableThe subscription plan the payment belongs to (free-form, e.g. Starter, Business). Omit or null for one-time payments.

Assuming the table is called transactions, here is an example of how such an SQL query may look like:

sql
SELECT
    id,
    user_id AS stats_user_id,
    total AS gross,
    total - tax AS net,
    'USD' AS currency,
    DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s') AS `time`
FROM
    transactions;
sql
SELECT
    id,
    user_id AS stats_user_id,
    total AS gross,
    total - tax AS net,
    'USD' AS currency,
    to_char(created_at, 'YYYY-MM-DD HH24:MI:SS') AS "time"
FROM
    transactions;

With Condition ​

Sometimes you may not want to count all payments as "valid". So you may only export the payments which pass a certain condition, such as having a "completed" status.

The query could look like this:

sql
SELECT
    id,
    user_id AS stats_user_id,
    total AS gross,
    total - tax AS net,
    'USD' AS currency,
    DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s') AS `time`
FROM
    transactions
WHERE
    status = 'completed';
sql
SELECT
    id,
    user_id AS stats_user_id,
    total AS gross,
    total - tax AS net,
    'USD' AS currency,
    to_char(created_at, 'YYYY-MM-DD HH24:MI:SS') AS "time"
FROM
    transactions
WHERE
    status = 'completed';

Now export the output of the query, save the file and then you can upload the file inside the app to start a new import!

INFO

Please note, the provided queries serve merely as examples. Your actual table structures and data might vary significantly. The implementation is completely up to you!

WARNING

The first row of your import file must be a heading row (a row in which each cell contains the key of the allowed fields)!

DANGER

Remember that Gross and Net must be stated in cents!

Importing Visitor Data ​

If you used another analytics tool before, you can bring your historical visitors over as well. Each row of the import file is one visitor.

Allowed Visitor Fields ​

KeyTypeDescription
timestring requiredThe time of the visit.
Format: Y-m-d H:i:s, before or equal now
visitor_hashstring nullableA unique id of the visitor. Required if you want to import page views for this visitor afterwards.
Optional fields
KeyTypeDescription
ipstring nullableThe ip of the visitor. (does not get stored)
user_agentstring nullableThe user_agent of the visitor. (does not get stored)
track_refererstring nullableThe tracking referer of the visitor.
track_sourcestring nullableThe tracking source of the visitor.
track_mediumstring nullableThe tracking medium of the visitor.
track_campaignstring nullableThe tracking campaign of the visitor.
track_termstring nullableThe tracking term of the visitor.
track_contentstring nullableThe tracking content of the visitor.
location_countrystring nullableThe location country of the visitor. (If the ip is set, we take the country that refers to it.)
location_regionstring nullableThe location region of the visitor. (If the ip is set, we take the region that refers to it.)
location_citystring nullableThe location city of the visitor. (If the ip is set, we take the city that refers to it.)
device_typestring nullableThe device type of the visitor. (If the user_agent is set, we take the device type that refers to it.)
device_platformstring nullableThe device platform (OS) of the visitor. (If the user_agent is set, we take the device platform that refers to it.)
device_browserstring nullableThe device browser of the visitor. (If the user_agent is set, we take the device browser that refers to it.)
page_entrystring nullableThe page the visitor entered your app on, e.g. /pricing.

A visitor whose visitor_hash is already known (tracked live or imported before) is skipped, so a re-import never changes existing data.

INFO

Imported visitors count as events against your plan, just like tracked ones.

Importing Page View Data ​

Page views belong to a visitor. Therefore, import your visitors first, then the page views. Each row is one page of one visitor.

Allowed Page View Fields ​

KeyTypeDescription
visitor_hashstring requiredThe visitor_hash of an already imported or tracked visitor.
pagestring requiredThe path of the viewed page, e.g. /pricing. Query strings and fragments are removed.
viewsinteger nullableHow often the visitor viewed this page. Defaults to 1.
timestring nullableThe time of the last view. Defaults to the time of the visitor.
Format: Y-m-d H:i:s

Rows of unknown visitors are skipped. Page views do not count as events against your plan.

WARNING

A page view import cannot be rolled back on its own. Rolling back the corresponding visitor import removes its page views as well.

Importing a Fathom Analytics Export ​

Coming from Fathom Analytics? You can upload a Fathom export as it is, no need to reshape it. In the Switch from another Tool section of the Data Imports page, select your project on the Fathom Analytics card, choose the CSV file and start the import.

Creating the Export in Fathom ​

In Fathom, create a new export with the following settings:

SettingValue
Data TypePageviews
TimezoneThe timezone of your SimpleStats team
Date GroupingDaily or Hourly
DimensionsPage, Referrer, UTM Parameters
(optional: AI Source, Country, Region, City, Browser, Device Type, Operating System)
MetricsPageviews, Entries, Page Visitors

How the Data Is Imported ​

Fathom only exports totals (e.g. "on October 15, 12 visitors came from laravel-news.com and entered on /blog"), not individual visitors. We therefore rebuild one visitor per entry, with its referrer, UTM parameters and entry page, and distribute the page views among these visitors.

As a result, the following numbers match your Fathom dashboard per day (or per hour with hourly grouping):

  • visitors
  • page views and viewers per page
  • entry pages
  • referrers and UTM parameters

The time of day within a day, and with it the bounce rate, is an approximation.

The import creates visitors and page views, so it counts like a visitor import against your plan. Rolling back a Fathom import removes all of its visitors and page views.