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(){arguments[0].timestamp=arguments[0].timestamp
    ||1*new Date();(s[z].q=s[z].q||[]).push(arguments);j=JSON;n='sqzlls';try{window.Storage&&(ls=localStorage,lsv=
    j.parse(ls.getItem(n))||[],lsv.push(j.stringify(arguments[0])),ls.setItem(n,j.stringify(lsv)))}catch(x){}},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",
            "firstname"     : "Jan",
            "lastname"      : "Schmidt",
            "gender"        : "M",
            "birthdate"     : "1985-12-31",
            "city"          : "Berlin",
            "country"       : "DE",
            "totalvalue"    : 69.95,
            "orderid"       : "12345",
            "currency"      : "EUR",
            "productamount" : 2,
            "content_ids"   : ["SKU123", "SKU456"]
        });
	
	</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.

Available properties:
Name Description
event The event you want to track. 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

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 don't have to pass this. Saved in client session. Optional
email Customer email Mandatory
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
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
productamount Number of bought products Optional
totalvalue Total value of purchase with 2 decimals (eg. 99.99) Mandatory
orderid Order reference of the purchase Mandatory
currency Currency of the purchase (e.g. GBP/EUR/USD) Optional
product_ids JSON array of Id(s) of the purchased product(s) (e.g. ["ABC123"] or ["ABC123","XYZ789"]) Optional

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 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
objectname Name of product Optional
totalvalue Value of product added with 2 decimals (eg. 99.99) Optional
currency Currency of the purchase (e.g. GBP/EUR/USD) Optional
product_ids JSON array of Id(s) of the product (e.g. ["ABC123"] or ["ABC123","XYZ789"]) Optional

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 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
objectname Name of product Optional
totalvalue Value of product viewed with 2 decimals (eg. 99.99) Optional
currency Currency of the purchase (e.g. GBP/EUR/USD) Optional
product_ids JSON array of Id(s) of the product or category (e.g. ["ABC123"] or ["ABC123","XYZ789"]) Optional

Event: ViewCategory

Event should be fired when someone views a category page.

Available properties:
Name Description
event ViewCategory 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
objectname Name of category Optional
currency Currency of the purchase (e.g. GBP/EUR/USD) Optional
category_id Id of the viewed category (e.g. ABC123) Optional

Event: Search

Event should be fired when someone searched for something on your website.

Available properties:
Name Description
event Search 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
keyword Search keyword Mandatory

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 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
value Value of your custom event Optional

Event: EmailUnsubscribe

Event should be fired when someone unsubscribe from your newsletter.

Available properties:
Name Description
event Search Mandatory
email Customer email Mandatory

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(),
        "productamount" => $order->getTotalItemCount(),
        "totalvalue"    => $order->getGrandTotal(),
        'currency'      => $order->getOrderCurrencyCode(),
        'orderid'       => $orderId,
        'newsletter'    => $newsletterOptin
        );


    $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 don't have to pass this. Saved in client session. Optional
email Customer email Mandatory
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
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
productamount Number of bought products Optional
totalvalue Total value of purchase with 2 decimals (eg. 99.99) Mandatory
orderid Order reference of the purchase Mandatory
currency Currency of the purchase (e.g. GBP/EUR/USD) Optional
product_ids JSON array of Id(s) of the purchased product(s) (e.g. ["ABC123"] or ["ABC123","XYZ789"]) Optional