---
# System prepended metadata

title: OS HConnect - HRV

---

# OS HConnect - HRV


## 1. OS Init Code

````html
<!--  -->

<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async=""></script>
<script>
  window.OneSignal = window.OneSignal || [];
  OneSignal.push(function() {
    OneSignal.init({
      appId: "a2d8db7a-8e82-4738-b396-b0693672ce3c",
    });
  });
</script>

<script>
if (localStorage.getItem("didUpdateCart")=="true") {
OneSignal.push(function () {
    var timestamp = Math.floor(Date.now() / 1000);
    OneSignal.sendTags({
        browse_update: "", // avoid sending ABP
        checkout_update: "", // avoid sending ACF
        cart_update: timestamp
    }).then(function (tagsSent) {
        console.log("tagsSent: ", tagsSent);
        localStorage.setItem("didClearCart","false");
        localStorage.setItem("didUpdateCart","false");        
    });
});
    
      
}
</script>

``````

Trigger
![](https://i.imgur.com/tfy8mg7.png)
![](https://i.imgur.com/nmF9pcO.png)




## 2. OS Add to Cart
```html 
<script>
localStorage.setItem("didUpdateCart","true");    
</script>
```
Trigger
![](https://i.imgur.com/9PBK3Ww.png)
![](https://i.imgur.com/b1VNQLk.png)
![](https://i.imgur.com/Sj5nIwZ.png)
![](https://i.imgur.com/jJ3D8Be.png)
![](https://i.imgur.com/yHoDoMT.png)

## 3. OS ClearCart
```html 
<script>  
  if (localStorage.getItem("didClearCart")  == "true" && window.location.href.search("checkouts") == -1) {
    if (document.querySelector("#cart-view").innerText.trim() == "Hiện chưa có sản phẩm") {
        // Cart is empty
        OneSignal.push(function () {
            OneSignal.sendTags({
                cart_update: "",
            }).then(function (tagsSent) {
                console.log("tagsSent: ", tagsSent);
                localStorage.setItem("didClearCart","false");
            });
        });
    }
  }
</script>
```
Trigger
![](https://i.imgur.com/WYEyqfw.png)

## OS ClearCart_Record
```html
<script>
localStorage.setItem("didClearCart","true");
 setTimeout(function(){ 
  if (document.querySelector("#cart-view").innerText.trim() == "Hiện chưa có sản phẩm") {    
    // Cart is empty
    OneSignal.push(function () {
      OneSignal.sendTags({
        cart_update: "",
      }).then(function (tagsSent) {
        console.log("tagsSent: ", tagsSent);
        localStorage.setItem("didClearCart","false");
      });
    });
  }                      
 }, 2000);   
</script>
```
Trigger
![](https://i.imgur.com/YQ9v3OB.png)
![](https://i.imgur.com/PlWeNbV.png)
![](https://i.imgur.com/Y1WeiCK.png)
![](https://i.imgur.com/s6lLzzj.png)
![](https://i.imgur.com/izPdsee.png)
![](https://i.imgur.com/M1AK3be.png)

## 4. OS BrowseProduct
```html 
<script>
var productName = document.querySelector("#detail-product>div.product-title>h1").innerText; // capture the name of the item
var categoryName = meta.product.type; // capture the name of the category
var salePrice = document.querySelector("#detail-product>div.product-price>span.pro-price").innerText; // capture discount price of product if applicable
OneSignal.push(function () {
    var timestamp = Math.floor(Date.now() / 1000);
    OneSignal.sendTags({
        browse_update: timestamp,
        category_update: timestamp,
        cart_update: "",
        checkout_update: "",
        product_name: productName,
        sale_price: salePrice,
        category_name: categoryName,
        page_url: window.location.host + window.location.pathname
    }).then(function (tagsSent) {
        // Callback called when tags have finished sending
        console.log("tagsSent: ", tagsSent);
    });
});
</script>
```
Trigger
![](https://i.imgur.com/VQQzGAE.png)

## 5. OS Checkout
```html 
<script>  
  var user_email = $("input[name='checkout_user[email]']").val();
  var user_name = "";
  if (user_email == "") {
    // user has not logged 
    $("#checkout_user_email").change(function () {
      user_email = $("#checkout_user_email").val();
    });
  }

  $("#billing_address_phone").change(function () {
    user_name = $("#billing_address_full_name").val();
    OneSignal.push(function () {
      var timestamp = Math.floor(Date.now() / 1000);
      OneSignal.sendTags({
        browse_update: "", // avoid sending ABP
        cart_update: "", // avoid sending AC
        user_name: user_name,
        user_email: user_email,
        checkout_update: timestamp,
      }).then(function (tagsSent) {
        console.log("tagsSent: ", tagsSent);
      });
    });  
  });
</script>
```
Trigger
![](https://i.imgur.com/eb42G4G.png)

## 6. OS Purchase+FetchSub
```html 
<script>
var callback = function (o) {
    console.log(o);
    window.localStorage.removeItem("ematic_email");
};

var email = Haravan.checkout.email;
localStorage.setItem('ematic_email', email);

if (email !=   undefined && email != "") {
    {{mailjet_subscribe}}(email,"addforce", { "data_source": "Ematic_API-Checkout" } ,callback); 
}  
  
OneSignal.push(function() {
    var timestamp = Math.floor(Date.now() / 1000);
    OneSignal.sendTags({
        browse_update: "",
        // avoid sending ABP
        cart_update: "",
        // avoid sending AC
        checkout_update: "",
        // avoid sending ACF
        purchase_update: timestamp
    }).then(function(tagsSent) {
        console.log("tagsSent: ", tagsSent);
    });
});  
</script>
```
Trigger
![](https://i.imgur.com/ia1rTSo.png)
![](https://i.imgur.com/hs8AXCW.png)

