If you manage a Shopify store and want to increase user engagement by displaying special content, deals, or sections to consumers after a certain time (for example, 12 hours after account creation), you've come to the correct spot. This step-by-step guide will teach you how to automatically display a section for customers who have had their account for over 12 hours.
Step 1: Automatically Tag New Customers at Registration
To begin with, tag new clients as soon as they register so that you can measure the time it takes to create their accounts. This tag will also be used to control the presentation of your special section.
- Navigate to Your Theme's Code:
- Go to Shopify Admin > Online Store > Themes.
- Select the theme you wish to modify and click Actions > Edit Code.
- Edit the Registration File:
- Open customers/register.liquid. File
- Search following code
<div class="field">
<input
type="text"
name="customer[first_name]"
id="RegisterForm-FirstName"
{% if form.first_name %}
value="{{ form.first_name }}"
{% endif %}
autocomplete="given-name"
placeholder="{{ 'customer.register.first_name' | t }}"
>
- Insert the Following Code: Paste this snippet after the <div class="field"> line:
<input type="hidden" id="customer_tags" name="customer[tags]" value="createdAt_{{ "now" | date: "%Y-%m-%d %H:%M:%S" }}"/>
Step 2: Create a New Section and Add Liquid Code
You will now build a section displaying content based on the account's establishment time.
- Create the New Section File:
- In your Shopify admin, go to Online Store > Themes.
- Click Actions next to your current theme and choose Edit Code.
- Under the Sections directory, click Add a new section and name it customer_section.
-
Add the Code to the Section File: In the newly created snippet custumer_section.liquid file, add the following code:
{% if customer %}
{% assign created_date = customer.tags | remove: 'createdAt_' | date: '%Y-%m-%d %H:%M:%S' %}
{% assign current_time = 'now' | date: '%s' %}
{% assign account_creation_time = created_date | date: '%s' %}
{% assign time_difference = current_time | minus: account_creation_time %}
{% assign hours_difference = time_difference | divided_by: 3600 %}
{% if hours_difference >= 12 %}
{{ section.settings.content }}
{% endif %}
{% endif %}
{% schema %}
{
"name": "Customer Session",
"settings": [
{
"type": "text",
"id":"content",
"label": "Content",
"default":"Welcome! You've been with us for more than 12 hours!"
}
],
"presets": [
{
"name": "Customer Session"
}
]
}
{% endschema %}
Step 3: Customize and Add the Section
- Go to Online Store > Themes > Customize.
- Click Add section and select Customer Session.
- Customize the content as needed and save your changes.
Conclusion: This solution allows you to automatically display specified sections to users who have had an account for more than 12 hours. It's a simple yet efficient technique to increase consumer engagement and encourage them to connect more with your store.