Back to Shopify Liquid
Sales Simulator
Shopify Liquid

Sales Simulator

A lightweight social proof popup that displays simulated recent purchase notifications. Automatically cycles through random names, locations, and time stamps using the current product's featured image and title.

EasySalesUrgency buildingSocial ProofCROProduct Page
152 lines · 3.8 KB
Setup 5–10 minutes 5 min read 152 lines
Key features
  • Dynamic product data integration
  • Configurable display intervals
  • Responsive mobile/desktop positioning
  • Auto-hide functionality
  • Manual close button
Best use cases
  • Building trust on new stores with low initial traffic.
  • Increasing conversion rates via social validation.
  • Adding visual activity to product detail pages.
Compatibility
  • Most Shopify themes

The code

Shopify Liquid
1<!--INICIO SIMULADOR DE VENTAS-->
2<style>
3 /* Estilos para el simulador de ventas */
4 .notification {
5 position: fixed;
6 width: 400px; /* Ancho del popup */
7 background-color: white;
8 border-radius: 12px;
9 padding: 10px;
10 z-index: 9999;
11 display: none;
12 color: black;
13 box-shadow: 0 0 10px rgba(0, 0, 0, 0.2); /* Sombra */
14 }
15
16 .notification img {
17 border-radius: 50%;
18 width: 50px;
19 height: 50px;
20 float: left;
21 margin-right: 10px;
22 }
23
24 .close-btn {
25 position: absolute;
26 top: 10px;
27 right: 10px;
28 cursor: pointer;
29 font-size: 17px;
30 color: black;
31 }
32
33 .notification div {
34 line-height: 17px; /* Interlineado */
35 }
36
37 #location {
38 font-weight: bold;
39 font-size: 14px;
40 }
41 #purchase{
42 font-size: 13px;
43 }
44 #time{
45 font-size: 12px;
46 }
47
48 /* Estilos específicos para dispositivos móviles */
49 @media only screen and (max-width: 600px) {
50 .notification {
51 top: 10px; /* Mantener en la parte superior en dispositivos móviles */
52 left: calc(50% - 200px); /* Centrar horizontalmente */
53 }
54 }
55
56 /* Estilos específicos para escritorio */
57 @media only screen and (min-width: 601px) {
58 .notification {
59 bottom: 10px; /* Mostrar en la parte inferior en escritorio */
60 left: 10px; /* Alinear a la izquierda */
61 }
62 }
63</style>
64
65
66<div class="notification" id="notification">
67 <div>
68 <!-- Imagen del producto -->
69 <img class="product-image" id="product-image" src="{{ product.featured_image | img_url: '100x100' }}" alt="{{ product.title }}">
70 <div class="close-btn" onclick="closeNotification()">X</div>
71 <div id="location"></div>
72 <div id="purchase"></div>
73 <div id="time"></div>
74 </div>
75</div>
76
77<script>
78 function closeNotification() {
79 document.getElementById('notification').style.display = 'none';
80 }
81
82 const locations = [
83 "Dinamarca",
84 "Toledo",
85 "Trujillo",
86 "Portugal",
87 "Cádiz",
88 "Madrid",
89 "Ica",
90 "Suecia",
91 "Ancash",
92 "Loreto",
93 "Lituania",
94 "Almería",
95 ];
96
97 const personNames = [
98 "Juan Gomez",
99 "Lucia Sanchez",
100 "Luis Gutierrez",
101 "Maria Garcia",
102 "Pedro Torres",
103 "Carmen Rodriguez",
104 "Carlos Hernández",
105 "Ana Gonzales",
106 "Rodrigo Pérez",
107 "Thalia Suarez",
108 "Jose Benavides",
109 "Diana Mendoza"
110 ];
111
112 // Tiempos (12 en total)
113 const times = [
114 "hace 9 minutos",
115 "hace 42 minutos",
116 "hace 15 minutos",
117 "hace 23 minutos",
118 "hace 7 minutos",
119 "hace 3 horas",
120 "hace 2 minutos",
121 "hace 5 horas",
122 "hace 1 minuto",
123 "hace 23 horas",
124 "hace 1 hora",
125 "hace 5 minutos"
126 ];
127
128 function showNotification() {
129 const notification = document.getElementById('notification');
130
131 const randomIndex = Math.floor(Math.random() * personNames.length);
132 const randomTimeIndex = Math.floor(Math.random() * times.length);
133
134 const productName = "{{ product.title }}";
135 document.getElementById('location').innerText = `${personNames[randomIndex]} de ${locations[randomIndex]} compró:`;
136 document.getElementById('purchase').innerText = `${productName}`;
137 document.getElementById('time').innerText = times[randomTimeIndex];
138
139 notification.style.display = 'block';
140
141 setTimeout(() => {
142 notification.style.display = 'none';
143 }, 8000);
144 }
145
146 // Inicialización de notificaciones
147 setTimeout(() => {
148 showNotification();
149 setInterval(showNotification, 48000);
150 }, 6000);
151</script>
152<!--FINAL SIMULADOR DE VENTAS-->

How to install Sales Simulator on your Shopify theme

This snippet belongs in sections/main-product.liquid, directly under the Add to cart button, where it reinforces the purchase decision. Expect the whole job to take about 5–10 minutes.

  1. 1From your Shopify admin, open Online Store → Themes, click the button on your live theme and choose Duplicate. Always work on a copy so you can roll back instantly.
  2. 2On the duplicated theme, click … → Edit code to open the theme code editor.
  3. 3Open sections/main-product.liquid in the file tree. If your theme uses different file names, search for the template that renders the area where you want the block to show up.
  4. 4Click Copy code on this page, then paste the snippet directly under the Add to cart button, where it reinforces the purchase decision.
  5. 5The snippet ships with its own scoped <style> block, so you do not need to touch base.css or theme.css. If you prefer to keep CSS centralised, move the contents of the style tag into your theme stylesheet and delete the inline block.
  6. 6Keep the <script> tag at the end of the snippet. It only runs once the surrounding markup exists in the DOM, so moving it higher up the file can break the behaviour.
  7. 7Click Save, then hit Preview and check the block on desktop, tablet and mobile widths.
  8. 8When you are happy with the result, publish the duplicated theme from Online Store → Themes → Actions → Publish.

How to customise it

Every value below lives inside the snippet, so you can adapt Sales Simulator to your brand without touching the rest of the theme.

  • Sizing — adjust the font-size values (17px, 14px, 13px) and the padding so the block carries the same visual weight as the elements around it.
  • Cornersborder-radius: 12px controls the roundness. Set it to 0 for a sharper editorial look, or increase it for a softer, app-like feel.
  • Images — replace the placeholder image URLs with your own assets. Upload them under Content → Files in Shopify admin and use the generated CDN URL, or reference a theme asset with {{ 'my-image.png' | asset_url }}.
  • Timing — the countdown duration is set in the script. Change the target time or the interval value to control how long the offer runs before it resets.
  • Responsive behaviour — the @media query defines the mobile breakpoint. Adjust the pixel value if your theme uses a different breakpoint scale.

Common mistakes to avoid

These are the issues merchants run into most often when installing a snippet like this one.

  • Editing the live theme directly. Duplicate it first — a single unbalanced Liquid tag can take a storefront down mid-campaign.
  • Pasting the code into the wrong file. Dropped into layout/theme.liquid instead of sections/main-product.liquid, this block will render on every page of the store, including ones where it makes no sense.
  • Renaming the CSS classes in the markup but not in the style block, or vice versa. The class names have to match exactly or the styling silently disappears.
  • Adding the snippet twice on the same page. The script targets its selector, so two copies can conflict or double-fire.
  • Running a countdown that resets on every page load and never actually expires. Shoppers notice fake urgency, and in the EU and UK it can breach consumer-protection rules.
  • Publishing without testing on a real phone. Most Shopify traffic is mobile, and layout problems almost always surface there first.

Performance notes

What this block costs you in load time, and how to keep that cost at zero.

  • The CSS is inline and scoped to this block, so it adds no extra network request. At a few kilobytes it has no measurable effect on your Lighthouse score.
  • The JavaScript is vanilla — no jQuery, no external library, no additional request. Keep it after the markup so it never blocks rendering.
  • Add loading="lazy" plus explicit width and height attributes to every image in the snippet. That prevents Cumulative Layout Shift, which is a Core Web Vitals ranking factor.
  • Run PageSpeed Insights before and after you add the block so you have a concrete number rather than a guess.

SEO & accessibility

How to add this block without damaging your on-page structure or your rich results.

  • Nothing in this snippet should replace your page <h1>. Keep product and page headings intact and use <h2> or <h3> for the block's own heading so the document outline stays clean.
  • Write a descriptive alt attribute for every image. Empty or generic alt text is one of the most common accessibility and SEO issues on Shopify stores.
  • If the block shows review or rating content, keep it consistent with the structured data your review app already outputs. Duplicating or contradicting rating markup can cost you the rich result entirely.
  • The block does not create a new URL, so there is no canonical or indexing change to make. It improves on-page engagement signals rather than crawlability.
Frequently asked questions

Sales Simulator — questions merchants ask

Will this snippet work with my theme?

It is built with standard Liquid, HTML and CSS, so it works with Dawn and virtually every Online Store 2.0 theme, as well as most vintage themes. The only thing that changes between themes is the file you paste it into — if yours has no sections/main-product.liquid, look for the equivalent template that renders the same area.

Do I need an app to use it?

No. This is theme code you own outright: no monthly fee, no third-party script tag, and no app that can break your storefront the next time it updates.

How long does it take to add “Sales Simulator” to a store?

Most merchants have it live in under fifteen minutes — duplicate the theme, paste the code, adjust the colours and copy, preview on mobile, publish.

The block appears but nothing happens. What is wrong?

That is almost always a script-order problem. Check that the script tag is still at the bottom of the snippet and that the markup was not pasted inside another script or a Liquid comment block. Open your browser console and look for an error naming the snippet's selector.

The styling looks broken after pasting. How do I fix it?

Confirm you copied the whole snippet including the closing style tag, then check whether one of your theme's own CSS rules is overriding it. If a theme rule wins, increase the specificity of the snippet's selector rather than scattering !important through the file.

Will it slow my store down?

Not meaningfully. It is inline markup with scoped CSS and at most a few lines of vanilla JavaScript — no external libraries, no extra HTTP request. Optimising your product images will always have a far bigger impact on load time.

Can I use it on a client store or a commercial project?

Yes. Every snippet in the MCO Hub library is free to copy, modify and ship on any store, including client work. Attribution is appreciated but not required.

Related snippets

Keep exploring