Tracking events

There are two ways to track data: Through front-end or back-end.
Front-end means that you will use a tracking pixel on your website. Back-end means you use server to server communication to track your data via our API.

The goal is to send events to us with user behavior, so we can create segments that you can use on the connected channels.
This integration guide will help you set up the event tracking.

Front-end tracking

Almost all tracking will be done through front-end.

Place the following personalized code snippet in the head section of every page you want to use tracking on.


	<script type="text/javascript">
	
	(function(s,q,u,e,z,l,y){s['SqueezelyObject']=z;s[z]=s[z]||function(){
    (s[z].q=s[z].q||[]).push(arguments)},s[z].l=1*new Date();l=q.createElement(u),
    y=q.getElementsByTagName(u)[0];l.async=1;l.src=e;y.parentNode.insertBefore(l,y)
    })(window,document,'script','https://squeezely.tech/tracker/<YOUR_IDENTIFIER>/sqzl.js','sqzl');
	
	</script>
                    


You can track Standard Events or Custom Events.
For example. if you want to track a pageview through the standard PageView event, use the following code:

	<script type="text/javascript">
	
        sqzl({
            "event" : "PageView"
        });
	
	</script>
						

That's all, your visitors are now being tracked!
Ofcourse, the more info we have the better your segments will be. To provide more data, use the available properties as shown in the documentation of the event.

Another example: Track a Purchase event:

	<script type="text/javascript">
	
        sqzl({
            "event"         : "Purchase",
            "email"         : "[email protected]",
            "firstname"     : "Jan",
            "lastname"      : "Schmidt",
            "gender"        : "M",
            "birthdate"     : "1985-12-31",
            "city"          : "Berlin",
            "country"       : "DE",
            "orderid"       : "12345",
            "currency"      : "EUR",
            "products"      : [
                                "id": "ABC123",
                                "name": "Product 1",
                                "category_id": "CAT_1",
                                "price": 29.99,
                                "quantity": 2
                              ]
        });
	
	</script>
                                

All events work this way, you can track as many events on a page as you want. Use the left menu to see which properties you can use with which events.

Event: PageView

Event should be fired when someone views a page.
Note: This event must be implemented on all pages, regardless if other events are triggered.

Available properties:
Name Description
event PageView Mandatory
campaign The identifier for this campaign. If this is in the url of your landing page as variable sqzl_campaign or utm_campaign, you can omit this. Saved in client session. Optional
source Source of the customer (e.g. facebook or adwords). If this is in the url of your landing page as variable sqzl_source or utm_source, you can omit this. Saved in client session. Optional

Event: Purchase

Event should be fired when someone makes a purchase.

Available properties:
Name Description
event Purchase Mandatory
campaign The identifier for this campaign. If this is in the url of your landing page as variable sqzl_campaign or utm_campaign, you can omit this. Saved in client session. Optional
source Source of the customer (e.g. facebook or adwords). If this is in the url of your landing page as variable sqzl_source or utm_source, you can omit this. Saved in client session. Optional
email Customer email Mandatory
firstname Customer firstname Mandatory
lastname Customer lastname Mandatory
gender Customer gender (M/F/U) Optional
birthdate Customer birthdate (yyyy-mm-dd) Optional
phone Customer phone Optional
postcode Customer postcode Optional
city Customer city Optional
country Customer country code (eg. NL) Optional
salelocation Where is a purchase made (online/offline) Optional
offlinelocation Identifier of physical store location Optional
orderid Order reference of the purchase. Used to calculate revenue correctly. Mandatory
currency Currency of the purchase (e.g. GBP/EUR/USD) Optional
newsletter Is the user opt-in for email/newsletter. Correct value are yes or no. Optional
products JSON array of product(s). Supported properties:

id unique id or SKU. Required.
name name of the product
category_id Unique id or SKU of the category
price Price of the single product, 2 decimals. Required.
quantity Quantity bought. Defaults to 1.
Example 1:
  {"id": "ABC123", "price": 29.99}
Example 2:
[
    {
        "id": "ABC123",
        "name": "Product 1",
        "category_id": "CAT_1",
        "price": 29.99,
        "quantity": 2
    },
    {
        "id": "XYZ_789",
        "name": "Product 2",
        "category_id": "CAT_2",
        "price": 39.99,
        "quantity": 1
    }
]
Mandatory

Event: PrePurchase

Fire the PrePurchase event when a user has shared details with you, but still has to confirm the payment.
For example fire the event just before a customer is redirected to an external payment environment.

Note: The PrePurchase event is not mandatory, however we highly recommend using it. Implementing this event will give you more accurate sales tracking and more complete profile information.

Available properties:
Name Description
event PrePurchase Mandatory
campaign The identifier for this campaign. If this is in the url of your landing page as variable sqzl_campaign or utm_campaign, you can omit this. Saved in client session. Optional
source Source of the customer (e.g. facebook or adwords). If this is in the url of your landing page as variable sqzl_source or utm_source, you can omit this. Saved in client session. Optional
email Customer email Mandatory
firstname Customer firstname Mandatory
lastname Customer lastname Mandatory
gender Customer gender (M/F/U) Optional
birthdate Customer birthdate (yyyy-mm-dd) Optional
phone Customer phone Optional
postcode Customer postcode Optional
city Customer city Optional
country Customer country code (eg. NL) Optional
salelocation Where is a purchase made (online/offline) Optional
offlinelocation Identifier of physical store location Optional
orderid Order reference of the purchase. Used to calculate revenue correctly. Optional
currency Currency of the purchase (e.g. GBP/EUR/USD) Optional
newsletter Is the user opt-in for email/newsletter. Correct value are yes or no. Optional
products JSON array of product(s). Supported properties:

id unique id or SKU. Required.
name name of the product
category_id Unique id or SKU of the category
price Price of the single product, 2 decimals. Required.
quantity Quantity bought. Defaults to 1.
Example 1:
  {"id": "ABC123", "price": 29.99}
Example 2:
[
    {
        "id": "ABC123",
        "name": "Product 1",
        "category_id": "CAT_1",
        "price": 29.99,
        "quantity": 2
    },
    {
        "id": "XYZ_789",
        "name": "Product 2",
        "category_id": "CAT_2",
        "price": 39.99,
        "quantity": 1
    }
]
Mandatory

Event: AddToCart

Event should be fired when someone adds something to their cart.

Available properties:
Name Description
event AddToCart Mandatory
campaign The identifier for this campaign. If this is in the url of your landing page as variable sqzl_campaign or utm_campaign, you can omit this. Saved in client session. Optional
source Source of the customer (e.g. facebook or adwords). If this is in the url of your landing page as variable sqzl_source or utm_source, you can omit this. Saved in client session. Optional
currency Currency of the product (e.g. GBP/EUR/USD) Optional
products JSON array of product(s). Supported properties:

id unique id or SKU. Required.
name name of the product
category_id Unique id or SKU of the category
price Price of the single product, 2 decimals. Required.
quantity Quantity added to cart. Defaults to 1.
Example 1:
  ["id": "ABC123"]
Example 2:
[
    {
        "id": "ABC123",
        "name": "Product 1",
        "category_id": "CAT_1",
        "price": 29.99,
        "quantity": 2
    },
    {
        "id": "XYZ_789",
        "name": "Product 2",
        "category_id": "CAT_2",
        "price": 39.99,
        "quantity": 1
    }
]
Mandatory

Event: ViewContent

Event should be fired when someone visits a product page on your website.

Available properties:
Name Description
event ViewContent Mandatory
campaign The identifier for this campaign. If this is in the url of your landing page as variable sqzl_campaign or utm_campaign, you can omit this. Saved in client session. Optional
source Source of the customer (e.g. facebook or adwords). If this is in the url of your landing page as variable sqzl_source or utm_source, you can omit this. Saved in client session. Optional
currency Currency of the product (e.g. GBP/EUR/USD) Optional
products JSON array of product(s). Supported properties:

id unique id or SKU. Required.
name name of the product.
category_id Unique id or SKU of the category.
price Price of the single product, 2 decimals.
Example 1:
  {"id": "ABC123"}
Example 2:
{
    "id": "ABC123",
    "name": "Product 1",
    "category_id": "CAT_1",
    "price": 29.99
}
Mandatory

Event: ViewCategory

Event should be fired when someone views a category page.

Available properties:
Name Description
event ViewCategory Mandatory
category_id Id of the viewed category (e.g. ABC123) Mandatory
campaign The identifier for this campaign. If this is in the url of your landing page as variable sqzl_campaign or utm_campaign, you can omit this. Saved in client session. Optional
source Source of the customer (e.g. facebook or adwords). If this is in the url of your landing page as variable sqzl_source or utm_source, you can omit this. Saved in client session. Optional
objectname Name of the viewed category Optional
currency Currency of the purchase (e.g. GBP/EUR/USD) Optional

Event: Custom

You can add a custom event to target people with certain website behavior.

Available properties:
Name Description
event Your custom event Mandatory
campaign The identifier for this campaign. If this is in the url of your landing page as variable sqzl_campaign or utm_campaign, you can omit this. Saved in client session. Optional
source Source of the customer (e.g. facebook or adwords). If this is in the url of your landing page as variable sqzl_source or utm_source, you can omit this. Saved in client session. Optional
value Value of your custom event Optional

Event: EmailOptIn

Event should be fired when someone unsubscribes from your newsletter.

Available properties:
Name Description
event EmailOptIn Mandatory
email Customer email Mandatory
newsletter Is the user opt-in for email/newsletter. Correct value are yes or no. Mandatory

Event: CompleteRegistration

Event should be fired when someone completes a registration/signup form.

Available properties:
Name Description
event CompleteRegistration Mandatory
campaign The identifier for this campaign. If this is in the url of your landing page as variable sqzl_campaign or utm_campaign, you don't have to pass this. Saved in client session. Optional
source Source of the customer (e.g. facebook or adwords). If this is in the url of your landing page as variable sqzl_source or utm_source, you don't have to pass this. Saved in client session. Optional

Tracking through back-end


Backend tracking is used to get a 100% attribution for your sales, so it is very important to set up.
There is only one event. See the PHP example code below:



                                
    $url = "https://squeezely.tech/api/v1/track";
    $fields = array(
        "event"         => "Purchase",
        "email"         => $email,
        "firstname"     => $firstname,
        "lastname"      => $lastname,
        "gender"        => $order->getCustomerGender(),
        "birthdate"     => $order->getCustomerDob(),
        "phone"         => $order->getShippingAddress()->getTelephone(),
        "postcode"      => $order->getShippingAddress()->getPostcode(),
        "city"          => $order->getShippingAddress()->getCity(),
        "country"       => $order->getShippingAddress()->getCountry(),
        "currency"      => $order->getOrderCurrencyCode(),
        "orderid"       => $orderId,
        "newsletter"    => $newsletterOptin ? "yes" : "no",
        "products"      => [
                                "id" => "ABC123",
                                "name"=> "Product 1",
                                "category_id" => "CAT_1",
                                "price" => 29.99,
                                "quantity" => 2
                            ]
        );


    $ch = curl_init();
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, count($fields));
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($fields));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'X-AUTH-ACCOUNT: <ACCOUNT_IDENTIFIER>',
        'X-AUTH-APIKEY: <API_KEY>'
        ));

    $result = curl_exec($ch);
    curl_close($ch);     

                                

Just replace the values with your values and you're ready to go!
The call will return a JSON response with the result.

Event: Purchase

Event should be fired when someone makes a purchase.

Available properties:
Name Description
event Purchase Mandatory
campaign The identifier for this campaign. If this is in the url of your landing page as variable sqzl_campaign or utm_campaign, you can omit this. Saved in client session. Optional
source Source of the customer (e.g. facebook or adwords). If this is in the url of your landing page as variable sqzl_source or utm_source, you can omit this. Saved in client session. Optional
email Customer email Mandatory
firstname Customer firstname Mandatory
lastname Customer lastname Mandatory
gender Customer gender (M/F/U) Optional
birthdate Customer birthdate (yyyy-mm-dd) Optional
phone Customer phone Optional
postcode Customer postcode Optional
city Customer city Optional
country Customer country code (eg. NL) Optional
salelocation Where is a purchase made (online/offline) Optional
offlinelocation Identifier of physical store location Optional
orderid Order reference of the purchase. Used to calculate revenue correctly. Mandatory
currency Currency of the purchase (e.g. GBP/EUR/USD) Optional
newsletter Is the user opt-in for email/newsletter. Correct value are yes or no. Optional
products Array of product(s). Supported properties:

id unique id or SKU. Required.
name name of the product
category_id Unique id or SKU of the category
price Price of the single product, 2 decimals. Required.
quantity Quantity bought. Defaults to 1.
Example 1:
  ["id" => "ABC123", "price" => 29.99]
Example 2:
[
    [
        "id" => "ABC123",
        "name" => "Product 1",
        "category_id" => "CAT_1",
        "price" => 29.99,
        "quantity" => 2
    ],
    [
        "id" => "XYZ_789",
        "name" => "Product 2",
        "category_id" => "CAT_2",
        "price" => 39.99,
        "quantity" => 1
    ]
]
Mandatory