> ## Documentation Index
> Fetch the complete documentation index at: https://moengage-sdk-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# User Login in AMP (Older Process)

## Track Login

<CodeGroup>
  ```HTML HTML lines wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  <button id="login" data-vars-unique-id="someUniqueId">Click here to track user login</button>
  ```
</CodeGroup>

<CodeGroup>
  ```HTML HTML lines wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  <amp-analytics type="moengage" id="moengage">
  <script type="application/json">
  {
  "vars": {
  "appId": "XXXXXXXXXXXXXXXX",
  "dataCenter": "sdk-01"
  },
  "triggers": {
      "clickTrigger": {
        "on": "click",
        "selector": "#login",
        "request": "event",
        "extraUrlParams": {
          "a": {
           "USER_ATTRIBUTE_UNIQUE_ID": "${unique-id}"
          },
          "e": "EVENT_ACTION_USER_ATTRIBUTE",
          "identifiers": {
              "moe_user_id": "${unique-id}"
          }
        }
      }
    }
  }
  </script>
  </amp-analytics>
  ```
</CodeGroup>

Here, "someUniqueId" is the unique ID with which you want to login the user

<Warning>
  Important

  After tracking the login, all further attributes and events tracking should have the "identifiers" object defined inside the tracking code (with the "moe\_user\_id") as above, until logout event is performed. Otherwise, that attribute or event tracking will not be associated with this logged-in user in your MoEngage dashboard.
</Warning>

For example, if we want to track the above logged-in user's last name-

<CodeGroup>
  ```HTML HTML lines wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  <button id="lastName" data-vars-last-name="lastNameOfLoggedInUser">Click here to track logged-in user's last name</button>
  ```
</CodeGroup>

<CodeGroup>
  ```HTML HTML lines wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  <amp-analytics type="moengage" id="moengage">
  <script type="application/json">
  {
  "vars": {
  "appId": "XXXXXXXXXXXXXXXX",
  "dataCenter": "sdk-01"
  },
  "triggers": {
      "clickTrigger": {
        "on": "click",
        "selector": "#lastName",
        "request": "event",
        "extraUrlParams": {
          "a": {
           "USER_ATTRIBUTE_USER_LAST_NAME": "${last-name}"
          },
          "e": "EVENT_ACTION_USER_ATTRIBUTE",
          "identifiers": {
              "moe_user_id": "someUniqueId" //because we logged-in the user with "someUniqueId" as the unique ID
          }
        }
      }
    }
  }
  </script>
  </amp-analytics>
  ```
</CodeGroup>

## Track Logout

<CodeGroup>
  ```HTML HTML lines wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  <button id="logout">Click here to track user logout</button>
  ```
</CodeGroup>

<CodeGroup>
  ```HTML HTML lines wrap theme={"theme":{"light":"github-light","dark":"github-dark"}}
  <amp-analytics type="moengage" id="moengage">
  <script type="application/json">
  {
  "vars": {
  "appId": "XXXXXXXXXXXXXXXX",
  "dataCenter": "sdk-01"
  },
  "triggers": {
      "clickTrigger": {
        "on": "click",
        "selector": "#logout",
        "request": "event",
        "extraUrlParams": {
          "a": {},
          "e": "MOE_LOGOUT"
        }
      }
    }
  }
  </script>
  </amp-analytics>
  ```
</CodeGroup>

<Warning>
  Important

  After performing the above Moengage logout event, do NOT send "identifiers" with any further tracking code. Because the user had logged-out and further attribute/event tracking must not be associated with this user.
</Warning>
