Skip to main content

Integrate Opticks Sensor JS using Shopify

In this tutorial we will install the Opticks Sensor JS using Shopify and send purchases to Opticks as conversions using a Custom Pixel.

First, go to your Shopify store admin.

Then click on Settings in the left sidebar, at the bottom:

shopify_1.png

Click on Customer Events

shopify_2.png

Select More Views and then Custom Pixels. Press on Add custom pixel

shopify_3.png

Name your custom pixel "Opticks"

shopify_4.png

Configure the pixel privacy settings:

  • Permission: Set to “Not required” - The pixel will always run.
  • Data sale: Set to “Data collected does not qualify as data sale.”

shopify_5.png

Now, in the code part, copy the following snippet:

//Replace this with your Opticks sensor ID
var sensorID = "REPLACE_ME";
var s = document.createElement('script');
s.src = "https://opticksprotection.com/o/" + sensorID;
document.body.appendChild(s);

//Conversions Code
var d = 0;
function c(s, h, r) {
if (!d) {
d = 1;
document.body.appendChild(Object.assign(document.createElement("img"), {
style: "display: none; width: 0; height: 0;",
src: "//opticksstatic.com/conversion?s="+s+"&h="+h+"&revenue="+r
}));
}
}
analytics.subscribe("checkout_completed", function(e) {
var m = document.cookie.match('(^|;)\\s*opticksid\\s*=\\s*([^;]+)')||[];
var rev = e.data.checkout.totalPrice?.amount || 0;
var s = m[2]||'', h = window.optHitId||'';
if (s || h) c(s, h, rev);
else window.addEventListener("opticksEvent", function (e) {
c(e.detail.s, e.detail.opticksClickId, rev);
});
});

It is vital that you replace the var sensorID = "REPLACE_ME" for your Opticks JS sensor id. You can find it in your Opticks Sensor JS configuration page here: https://app.optickssecurity.com/setup/sensor-js

The Sensor ID is the last part after the /o/ segment, see the following example with the Sensor ID highlighted:

shopify_6.png

Copy it, and replace the code snippet "REPLACE ME" for your Sensor ID. The result should look similar to this:

shopify_7.png

After that, click Save and then Connect

shopify_8.png

shopify_9.png

Finally, go back to your Customer Events screen and make sure the pixel is Connected.

shopify_10.png