Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
3841C1144E1495DF4C3752CA /* boat.png in Resources */ = {isa = PBXBuildFile; fileRef = D20F48E81C4AB68DA9666435 /* boat.png */; };
3AD0D195591655CD7DF4BDB9 /* MapLayerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E30250B9C564E339DB5564CF /* MapLayerViewController.swift */; };
3D6085BE493F8C112445FAE0 /* MarkerEventsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3A66A9AD0A36086F2FAFAE15 /* MarkerEventsViewController.swift */; };
3E8D6EAC2F744A8200B608A8 /* GoogleMapsAttributionManaging.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3E8D6EAB2F744A7F00B608A8 /* GoogleMapsAttributionManaging.swift */; };
3EB5E34CE2DAAC36D547B7FA /* step2.png in Resources */ = {isa = PBXBuildFile; fileRef = 61EC340E5BD79BE2FB947774 /* step2.png */; };
432140AD81C292CF700CA7CE /* VisibleRegionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9D352205B6B3A8624B7640B1 /* VisibleRegionViewController.swift */; };
4336E0BDE21D982CE4078DDC /* step5.png in Resources */ = {isa = PBXBuildFile; fileRef = 3EB880171F8782BB95056A63 /* step5.png */; };
Expand Down Expand Up @@ -134,6 +135,7 @@
392A7D132855C21094CFB021 /* australia-large.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "australia-large.png"; sourceTree = "<group>"; };
3A66A9AD0A36086F2FAFAE15 /* MarkerEventsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarkerEventsViewController.swift; sourceTree = "<group>"; };
3A7D2BC402119B009115B458 /* walking_dot@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "walking_dot@3x.png"; sourceTree = "<group>"; };
3E8D6EAB2F744A7F00B608A8 /* GoogleMapsAttributionManaging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GoogleMapsAttributionManaging.swift; sourceTree = "<group>"; };
3EB880171F8782BB95056A63 /* step5.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = step5.png; sourceTree = "<group>"; };
401F0FC38C20C76F7D1C0A47 /* step8.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = step8.png; sourceTree = "<group>"; };
4162E354E88F4EFE2CF145C0 /* GoogleMapsSwiftXCFrameworkDemos.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GoogleMapsSwiftXCFrameworkDemos.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -231,6 +233,14 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
3E8D6EAA2F744A4D00B608A8 /* Attribution */ = {
isa = PBXGroup;
children = (
3E8D6EAB2F744A7F00B608A8 /* GoogleMapsAttributionManaging.swift */,
);
path = Attribution;
sourceTree = "<group>";
};
49D5CD2CC2E5C5341C1AA1A8 /* Frameworks */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -398,6 +408,7 @@
D7D66D616DE2CE337B6E8208 /* Swift */ = {
isa = PBXGroup;
children = (
3E8D6EAA2F744A4D00B608A8 /* Attribution */,
8C8A275114BA9A7F834826D9 /* Samples */,
382782429644E90B5A1447EA /* AppDelegate.swift */,
5F3ADD43B8D07F8EF4F9D50A /* SDKConstants.swift */,
Expand Down Expand Up @@ -592,6 +603,7 @@
48429416E1B15AF62D26CCBB /* FixedPanoramaViewController.swift in Sources */,
E657F17EADC44732C279A8C6 /* PaddingBehaviorViewController.swift in Sources */,
32F4182C033B514D3D3EBD8E /* DataDrivenStylingBasicViewController.swift in Sources */,
3E8D6EAC2F744A8200B608A8 /* GoogleMapsAttributionManaging.swift in Sources */,
F9D8F90BCD913C0935C98FBC /* AnimatedCurrentLocationViewController.swift in Sources */,
600FDFFB20EC325284FC28C3 /* DoubleMapViewController.swift in Sources */,
5FBAE15456D466E352347E97 /* PanoramaViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2026 Google LLC. All rights reserved.
//
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
// file except in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
// ANY KIND, either express or implied. See the License for the specific language governing
// permissions and limitations under the License.

import GoogleMaps

/// Protocol for managing Google Maps SDK usage attribution for sample applications.
protocol GoogleMapsAttributionManaging {
/// Adds attribution tracking for the specified view controller.
/// - Parameter viewController: The view controller to track attribution for.
func addAttribution(for viewController: UIViewController)
}

/// Default implementation of GoogleMapsAttributionManaging that automatically
/// generates attribution IDs based on view controller class names.
final class GoogleMapsAttributionManager: GoogleMapsAttributionManaging {
/// Adds attribution tracking by deriving a sample name from the view controller's class name.
///
/// The attribution ID follows the format: `gmp_git_iosmapssamples_v{majorVersion}_{sampleName}`
/// where `sampleName` is the class name with "ViewController" suffix removed and lowercased.
///
/// Example: `BasicMapViewController` becomes `basicmap`
///
/// - Parameter viewController: The view controller to generate attribution for.
func addAttribution(for viewController: UIViewController) {
let majorVersion = GMSServices.sdkVersion().components(separatedBy: ".").first ?? "10"
let className = String(describing: type(of: viewController))
let sampleName = className.replacingOccurrences(of: "ViewController", with: "").lowercased()
let attributionID = "gmp_git_iosmapssamples_v\(majorVersion)_\(sampleName)"
GMSServices.addInternalUsageAttributionID(attributionID)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ import GoogleMaps
import UIKit

class BasicMapViewController: UIViewController {
/// Manages Google Maps SDK usage attribution for this sample.
private let attributionManager: GoogleMapsAttributionManaging = GoogleMapsAttributionManager()
var statusLabel: UILabel!

override func viewDidLoad() {
super.viewDidLoad()

// Register this sample with Google Maps for usage tracking
attributionManager.addAttribution(for: self)
// Seattle coordinates
let camera = GMSCameraPosition(latitude: 47.6089945, longitude: -122.3410462, zoom: 14)
let options = GMSMapViewOptions()
Expand Down
Loading