Is there any code I can put in the HTML section of a page so that when a customer clicks on a link it automatically adds a tag to their account? (They will be logged in before doing this).
Thanks.
The original poster asks how to automatically add a tag to a logged-in customer’s account when they click a link on their Shopify store.
Proposed Solutions:
JavaScript + Server-Side API: One user suggests using JavaScript to capture the link click and send an AJAX request to a custom API endpoint that adds the tag. This requires server-side code (PHP, Ruby on Rails, etc.) to handle the tagging logic.
Third-Party Apps: Another respondent notes this functionality isn’t natively available in Shopify and recommends using third-party apps or building a custom app.
Shopify Flow: A user mentions Shopify Flow as a potential automation tool for adding/removing customer tags based on certain actions, though it’s unclear if it supports link-click triggers specifically.
Status: The discussion presents multiple approaches but no definitive, ready-to-use solution. Implementation would require custom development or third-party tools.
Is there any code I can put in the HTML section of a page so that when a customer clicks on a link it automatically adds a tag to their account? (They will be logged in before doing this).
Thanks.
To add a tag to a customer’s account when they click on a link, you will need to use JavaScript and/or a server-side language such as PHP or Ruby on Rails. Here’s a basic example using Javascript:
HTML:
bashCopy code
<a href="#" id="add-tag-link">Add Tag</a>
Javascript:
javascriptCopy code
document.getElementById("add-tag-link").addEventListener("click", function(event) { event.preventDefault(); // Send an AJAX request to your server to add the tag to the customer's account // You'll need to replace "YOUR_API_ENDPOINT" with the actual URL of your API endpoint that adds the tag fetch("YOUR_API_ENDPOINT", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ tag: "your-tag" }) }) .then(response => response.json()) .then(data => { // Do something with the response from the server console.log(data); }) .catch(error => { // Handle any errors that occur console.error(error); }); });
This example sends an AJAX request to your server to add the tag when the link is clicked. You’ll need to replace “YOUR_API_ENDPOINT” with the actual URL of your API endpoint that adds the tag. The response from the server can then be used to display a message to the customer or update the page in some other way.
Regenerate response
It is not possible unless you use some third party app or build a custom app to cater your needs
Thanks!
You can use Shopify Flow for this kind of action, except I am unsure if this can be set up when customer clicks on a link, but you can be as creative as you can.
There is an option to automatically add and remove tags from customers after certain action happened.