# Sales tracking

Sales can be tracked by Pickzen once configured. Pickzen will differentiate between direct sales and indirect sales:

* **Direct sales**: Sales of products that have been recommended by Pickzen.
* **Indirect sales**: Sales of products not recommended by Pickzen. This is important in Assistants that don't recommend products, for example, a Sizer. Pickzen will claim an indirect sale only if the customer previously completed an Assistant.

{% hint style="info" %}
The Sales module is disabled by default and it is only eligible for certain accounts. Write to us to evaluate your case.
{% endhint %}

### Shopify

In order to track sales from products purchased in Shopify, log into your Shopify store and go to Settings / Checkout / Order processing / Additional scripts and add the following code:

```javascript
{% if first_time_accessed %}<script>var pzOrderId={{order.order_number}};if(pzOrder={{checkout.order.line_items|json}} || {{order.line_items|json}},pzOrder){for(var pzProducts=[],pzI=0;pzI<pzOrder.length;pzI++){var line=pzOrder[pzI],gId=(line.product_id||line.product.id).toString();pzProducts.push({id:line.variant_id.toString(),gId:gId,price:parseFloat(line.price),quantity:line.quantity})}var pzTimer=setInterval(function(){window.pzIntegrationLoaded&&(clearInterval(pzTimer),window.pzConvertionTracker.notify(pzProducts,{order:pzOrderId}))},1e3)}</script>{% endif %}
```

Example:

![](/files/-MAfAchqXv5ZgWRtbbC1)

### Shopify + Recharge v1

In order to track subscription sales from Recharge v1, first ensure you followed the configuration steps for Shopify. Once done, open the Recharge app in your Shopify store, and click on *Checkout*:

![](/files/-MAf9x_21jiWj_y9copH)

Then, add the following code to the *Thank you page,* replacing first the *XXXXXXXX* code with your userId:

```javascript
<script async src="https://admin.pickzen.com/client/id/XXXXXXXX"></script>

{% if first_time_load %}<script>function parseHtmlEntities(r){return r.replace(/&#([0-9]{1,3});/gi,function(r,t){var e=parseInt(t,10);return String.fromCharCode(e)})}var pzOrderId={{order_number}},pz_products=[];{% for item in line_items %}pz_products.push({id:"{{item.variant_id}}",gId:"{{item.product_id}}",price:{{item.price}},quantity:{{item.quantity}}});{% endfor %}var pzTimer=setInterval(function(){var r;window.pzIntegrationLoaded&&(clearInterval(pzTimer),(r=parseHtmlEntities("{{attributes.pzRechargeData}}"))&&(r=JSON.parse(r)).forEach(function(r){pzConvertionTracker.notify(pz_products,{order:pzOrderId},2,JSON.stringify(r))}))},1e3);</script>{% endif %}
```

Example:

![](/files/-MAfDJVmLA4ZwUzLxSIk)

{% hint style="info" %}
You can get your userId in Integrations / Your Website / Pickzen Code
{% endhint %}

Finally, you need to add this code into Integrations / Your Website / Developers / Integration code:

```javascript
window.pickzen.onCompletion = function(code, products) {
  jQuery.getJSON('/cart.js', function(cart) {
    var rd;

    if (cart.attributes.pzRechargeData) {
      rd = JSON.parse(cart.attributes.pzRechargeData);
    } else {
      rd = [];
    }

    var data = window.pickzen.utils.getByKey(rd, 'code', code);
    if (!data) {
      data = {
        code: code,
        ct: code + ',0:0',
        pt: []
      };
      rd.push(data);
    }

    products.forEach(function(p) {
      if (!window.pickzen.utils.getByKey(data.pt, 'id', p.id)) {
        data.pt.push(p);
      }
    });

    jQuery.post('/cart/update.js', "attributes[pzRechargeData]=" + JSON.stringify(rd));
  });
};
```

### Shopify + Recharge v2

In order to track subscription sales from Recharge v2, simply ensure you followed the configuration steps for Shopify.

### Other platforms

Go to Integrations / Your site and enter the fragment of the page that corresponds with your confirmation URL:

<figure><img src="/files/jv9O72dpYWUnIuqrZunc" alt=""><figcaption></figcaption></figure>

Below, in the Code to get purchased products, you can enter your custom JavaScript code to fetch the purchased products and send them to Pickzen:

<figure><img src="/files/wslVlYpNmWhp3m6DEJHL" alt=""><figcaption></figcaption></figure>

```
var pzOrderId = orderId;
var pzProducts = products; 

var pzTimer = setInterval(function() {
    if (window.pzIntegrationLoaded) {
        clearInterval(pzTimer);
        window.pzConvertionTracker.notify(pzProducts, {
            order: pzOrderId
        });
    }
}, 1000);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.pickzen.com/insight/sales.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
