Mechanic is a development and ecommerce automation platform for Shopify. :)
Use this task to prompt your users for a code, redirecting them to an appropriate destination based on what they enter. Some assembly required, with sample Javascript and HTML provided. :)
Runs . Configuration includes redirects and codes, require case sensitive codes, and invalid code message.
Use this task to prompt your users for a code, redirecting them to an appropriate destination based on what they enter. Some assembly required, with sample Javascript and HTML provided. :)
Configure this task by filling in redirect URLs on the left, and a series of codes for each redirect on the right. The intent is to route users to the appropriate redirect, based on the code they enter.
This task doesn't run automatically. Instead, it generates some Javascript that's automatically embedded into your online storefront, redirecting the user when they enter a code that matches one of the redirects you've configured.
You can prompt the user for a code yourself, and pass the result to the function attemptRedirectByCode
, like this:
<script>
attemptRedirectByCode(prompt('Enter your code here:'))
</script>
Or, modify this HTML to set up a form for your users:
<form id="redirect-form">
<input type="text" placeholder="Enter your code here">
</form>
<script>
document.getElementById('redirect-form').onsubmit = function (event) {
event.preventDefault();
var input = event.target.children[0];
attemptRedirectByCode(input.value) || input.select();
};
</script>
Mechanic is designed to benefit everybody: merchants, customers, developers, agencies, Shopifolks, everybody.
That’s why we make it easy to configure automation without code, why we make it easy to tweak the underlying code once tasks are installed, and why we publish it all here for everyone to learn from.
(By the way, have you seen our documentation? Have you joined the Slack community?)
var redirects = {{ options.redirects_and_codes__keyval_multiline | json }}; var codesToRedirects = {}; Object.getOwnPropertyNames(redirects).forEach(function (redirect) { redirects[redirect].split("\n").map(function (code) { {% if options.require_case_sensitive_codes__boolean %} return code.toLowerCase().trim(); {% else %} return code.trim(); {% endif %} }).forEach(function (code) { codesToRedirects[code] = redirect; }); }); window.attemptRedirectByCode = function (code) { {% unless options.require_case_sensitive_codes__boolean %}code = code.toLowerCase();{% endunless %} code = code.trim(); if (codesToRedirects[code]) { window.location.href = codesToRedirects[code]; return true; } else { alert({{ options.invalid_code_message__required | json }}); return false; } };
{"/pages/secret-one"=>"one\num\nuno", "/pages/secret-two"=>"two\ndois\ndos", "/pages/secret-three"=>"three\ntrês\ntres"}
That code wasn't valid - try again.