How can I force SSL in Google Tag Manager?

Member

by dorothea , in category: SEO Tools , a year ago

How can I force SSL in Google Tag Manager?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

2 answers

Member

by pietro , a year ago

@dorothea 

To force SSL in Google Tag Manager, you can follow these steps:

  1. Log in to your Google Tag Manager account.
  2. Select the container where you want to force SSL.
  3. Click on "Tags" in the left-hand menu.
  4. Click on "New" to create a new tag.
  5. Give your new tag a name, such as "Force SSL".
  6. Click on "Tag Configuration".
  7. Select "Custom HTML" as the tag type.
  8. In the "HTML" field, paste the following code:<script> if (location.protocol != "https:") { location.href = "https:" + window.location.href.substring(window.location.protocol.length); } </script>
  9. Click on "Triggering".
  10. Click on "New" to create a new trigger.
  11. Give your new trigger a name, such as "All Pages".
  12. Select "Page View" as the trigger type.
  13. Under "Trigger Fires On", select "All Pages".
  14. Click on "Save" to save your trigger.
  15. Under "Triggering", select the trigger you just created.
  16. Click on "Save" to save your tag.
  17. Click on "Submit" to publish your changes.


This code will check if the current page is being served over HTTPS. If it is not, it will redirect the page to the HTTPS version of the page. By setting this tag to fire on all pages, you will force SSL on your entire website via Google Tag Manager.

by jose_gulgowski , 4 months ago

@dorothea 

Note: Before implementing any changes to your website or Google Tag Manager, it is recommended to create a backup and test it in a staging environment to ensure it does not cause any issues on your live website.

  1. Log in to your Google Tag Manager account.
  2. Select the container where you want to force SSL.
  3. Click on "Tags" in the left-hand menu.
  4. Click on "New" to create a new tag.
  5. Give your new tag a name, such as "Force SSL".
  6. Click on "Tag Configuration".
  7. Select "Custom HTML" as the tag type.
  8. In the "HTML" field, paste the following code:
1
2
3
4
5
<script>
if (location.protocol != "https:") {
  location.href = "https:" + window.location.href.substring(window.location.protocol.length);
}
</script>


  1. Click on "Triggering".
  2. Click on "New" to create a new trigger.
  3. Give your new trigger a name, such as "All Pages".
  4. Select "Page View" as the trigger type.
  5. Under "Trigger Fires On", select "All Pages".
  6. Click on "Save" to save your trigger.
  7. Under "Triggering", select the trigger you just created.
  8. Click on "Save" to save your tag.
  9. Click on "Submit" to publish your changes.


This code will check if the current page is being served over HTTPS. If it is not, it will redirect the page to the HTTPS version of the page. By setting this tag to fire on all pages, you will force SSL on your entire website through Google Tag Manager.


Remember to test this implementation thoroughly to ensure it works as expected before deploying it to your live website.