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
WHERE
    1;

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;

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)

Coming soon: In many cases, historical login data for users isn't readily available. To address this, we're introducing an upcoming feature that allows for the optional inclusion of a last_known_activity field. 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 will 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 enhancement aims to provide a richer, more accurate representation of your historical user engagement over time.

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 ...)

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
WHERE
    1;

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';

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!