3

I'm using Angular 8 Server-Side-Rendering (SSR) on Firebase Hosting. App is deployed by firebase function. Now I'm struggling how to add ads.txt from Google Adsense and where ads.txt should be placed in my project.

The project tree

  1. I convert app in main directory with npm run build:ssr
  2. Next I copy converted dist directory to functions
  3. And finally when dist dir appends in functions dir I use firebase deploy

If it will be placed in right directory, does 'firebase deploy' will upload ads.txt to main directory?

Maybe I should upload file in another way?

Any help would be appreciated. Thanks Stack!

2 Answers2

4

After placing the ads.txt file into your src directory, you need to add the file to the assets array in your angular.json file. Then it will be placed into the root of your project after build.

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "myproject": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:component": {
          "style": "sass"
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/myproject/browser",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/robots.txt",
              "src/ads.txt",
              "src/sitemap.xml",
              "src/assets"
            ],
...
  • I have localized projects. It does not work for me. Can you check please my post? https://stackoverflow.com/questions/72318108/how-to-add-app-ads-txt-to-angular-localized-project-on-firebase-hosting – Yury Matatov May 22 '22 at 05:39
0

I figured it out through trial and error.

If anyone will stuck on this it is very easy.

  1. Convert app with npm run build:ssr
  2. Copy generated dist dir to functions dir
  3. Copy ads.txt to functions/dist/browser
  4. Right now you are ready to deploy your app through firebase deploy command
  5. After deploy, you can check if ads.txt loaded successfully http://example.com/ads.txt

Whole tree should look like this project tree